npm install sh-area-select
下载后项目就会多一个node_modules目录,将node_modules中的插件目录移动到components下
demo.vue
import shAreaSelect from '../../components/sh-area-select/sh-area-select.vue'
//demo
<template>
<div class="demo">
<shAreaSelect ref="areaselect" :defaultValue="defaultAddress" @callback="result" :items="district"></shAreaSelect>
</div>
</template>
<script>
import shAreaSelect from '../../components/sh-area-select/sh-area-select.vue'
export default {
data() {
return {
district: [],
defaultAddress: {}
}
},
components: {
shAreaSelect
},
onLoad() {
this.getData()
},
methods: {
result(value) {
console.log('value', value)
},
getData() {
//获取数据
数据格式为
district:[
{c:[{c:[{c:[],n:'东城区',pid:2,v:3},{c:[],n:'西城区',pid:2,v:203}],n:'北京市',pid:1,v:2}],n:'北京市',pid:0,v:1},
{c:[{c:[{c:[],n:'河东区',pid:7363,v:7364},{c:[],n:'和平区',pid:7363,v:7364}],n:'天津市',pid:7362,v:7363}],n:'天津市',pid:0,v:7362},
]
}
}
}
</script>