vue vant Area组件使用详解

官网中给的内容太少,引入官网中的Area例子之后,发现弹出来的组件里并没有数据。

1.下载areaList.js并在使用的模板中引用 官方网站 areaList.js

import areaList from '../../assets/area/area.js'

2.main.js引入并注册(一般与Popup一起使用)

import { Area, Popup } from 'vue-router' Vue.use(Area) Vue.use(Popup)

3.template中,基础用法配置显示列,需要传入一个area-list属性

<van-cell is-link @click="showPopup" v-model="carmodel">选择需要显示的城市</van-cell> <van-popup v-model="show" position="bottom" :style="{ height: '50%' }"> <van-area :area-list="areaList" :columns-num="2" ref="myArea" title="标题" @change="onChange" @confirm="onConfirm" @cancel="onCancel"/> </van-popup>

4.script中,api与方法

export default { data() { return { areaList, show:false, carmodel:'' } }, methods:{ // 弹出层显示 showPopup() { this.show = true; }, //value=0改变省,1改变市,2改变区 onChange(picker, index, value){ let val = picker.getValues(); console.log(val)//查看打印 let areaName = '' for (var i = 0; i < val.length; i++) { areaName = areaName+(i==0?'':'https://www.jb51.net/')+val[i].name } this.carmodel = areaName }, //确定选择城市 onConfirm(val){ console.log(val[0].name+","+val[1].name) this.show = false//关闭弹框 }, //取消选中城市 onCancel(){ this.show = false this.$refs.myArea.reset()// 重置城市列表 } } }

5.效果图

vue vant Area组件使用详解

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/077e8d14385a983fc3d01cc5c17f67e7.html