在使用avue表單時,若想在表單中進行資料請求時,可以使用下面的方法:
{ label: "補貼型別", prop: "sub_type_msg", search: true, type: "select", dicUrl: "/admin/hadoop/not_auth/subType", dicMethod: "post", props: { label: "value", value: "key" }, filterable: true //開啟搜索功能 }
完整示例:
<avue-form :option="option" v-model="obj"></avue-form> <script> var baseUrl = 'https://cli.avuejs.com/api/area' export default { data() { return { obj: { province:'',//系結的prop值 }, option: { labelWidth: 100, column: [ { label: '單選', prop: 'province', type: 'select', props: { label: 'name', value: 'code' }, typeslot: true, dicUrl: `${baseUrl}/getProvince`, dicMethod: "post", typeformat(item, label, value) { return `值:${item[label]}-名:${item[value]}` }, rules: [ { required: true, message: '請選擇省份', trigger: 'blur' } ] } ] } } }, methods:{ handleSubmit(form){ this.$message.success(JSON.stringify(this.form)) } } } </script>
提示:
(1)dicUrl: `${baseUrl}/getCity/{ {key}}`,若需要傳引數,可以直接進行拼接
(2)如果是post請求,需要傳遞多個引數,就只能單獨寫一個事件,呼叫介面,進行賦值,要注意的是,如果是嵌套在表格中的請求,有時頁面資料可能不會更新,此時可以使用getSelectOption()方法,具體如下:
getSelectOption() { console.log(this.$refs.crud); var stallIndex =this.findObject(this.table.option.column,'stall_id'); console.log(stallIndex); this.$axios({ method: "post", url: "/admin/merchant/water_log/getStallList" }) .then(res => { console.log(res); stallIndex.dicData = DIC.STALL =res.data; }) .catch(error => {}); },
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/73753.html
標籤:JavaScript
上一篇:(十一)動態組件 & 異步組件
