最近做項目用到vue+iview Switch 開關,遇到兩個問題
問題1:直接引用開關組件 組件在頁面中顯示不出來 如:<Switch v-model="switch1" @on-change="change" />
解決:<i-switch v-model="switch1" @on-change="change" />這樣就可以了
問題2:從后台獲取數據回顯的時候報錯 如:Value should be trueValue or falseValue
解決:
<template> <i-switch v-model="data.switchShow" size="large" true-value="true" false-value="false"> <span slot="open">開啟</span> <span slot="close">禁用</span> </i-switch> </template> <script> export default { data() { return { data: { switchShow: false, }, } }, mounted() { axs.get('').then(res => { this.data= {//重新賦值switchShow屬性 因為請求之后switchShow屬性會被清空,,清空之后沒有默認值,v-model是雙向數據綁定 沒有值所以會報錯
switchShow: res.data
}
})
}
} </script>
注:如有紕漏請大家及時指出!嘿嘿