1. 程式人生 > >select預設值設定

select預設值設定

<Select v-model="AllproductsCode" placeholder="所有產品" style="width:150px" @on-change="AllproductsChange" class="mr20 ml50">
  <Option v-for="item in AllproductsList" :value="item.productCode" :key="item.productCode">{{ item.productName }}
</Option>
</Select>

exportdefault{
   data(){
        retrun{
            AllproductsCode:"code",
            AllproductsList:[]
        }
    },
    methods:{
        AllproductsChange(value){
            this.AllproductsCode= value
        }
    },
created() {
    // 所有產品
    this.http
      .post(BASE_URL + "請求路徑", {})
      .then(data => {
        if (data.code == "success") {
		this.AllproductsList = data.data;
		this.AllproductsList.splice(0,0,{ productCode: "code", productName: "所有產品" })
        }
      })
      .catch(err => {
        console.log(err);
      });
  },
}