Global introduction
import Vant from 'vant'; //嫌麻烦就全部一次导出,虽然包会稍微有点大
import 'vant/lib/index.css'; //注意导入全局的这个css,否则布局组件无法正确使用
Vue.use(Vant)
Drop-down box
Only radio, no multiple selection
returns the object obj, filling Picker, and takes the selected object ID
<div>
<van-field readonly clickable name="picker" :value="selectedClassify" label="分类"
placeholder="点击选择分类" @click="showPicker = true" />
<van-popup v-model="showPicker" position="bottom">
<van-picker show-toolbar :columns="columns" value-key="name" @confirm="onConfirm" @cancel="showPicker = false" />
</van-popup>
</div>
export default {
data() {
return {
selectedClassify: [],
columns: [{id:1, name:"名称A"}, {id:2, name:"名称B"}]
};
},
methods: {
onConfirm(obj) {
this.selectedClassify.push(obj.id);
this.showPicker = false;
}
}
};
checkbox checkbox
<div>
<van-checkbox-group v-model="selectedClassify" direction="horizontal">
<van-checkbox shape="square" v-for="item in tags" v-bind:name="item.id" >{{item.name}}</van-checkbox>
</van-checkbox-group>
</div>
export default {
data() {
return {
selectedClassify: [],
tags: []
};
},
methods: {
}
};
Note: This v-bind to on the v-for later, or else the first element selectedClassify is item.id string not understand why
notification
this.$toast('创建成功')
或者
this.$notify('成功')