qingwei-li / vue-region-picker Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED]
Home Page: http://qingwei-li.github.io/vue-region-picker/
License: Do What The F*ck You Want To Public License
[DEPRECATED]
Home Page: http://qingwei-li.github.io/vue-region-picker/
License: Do What The F*ck You Want To Public License
业务需求,可能有的地方需要三级联动,有的地方需要二级联动.
目前使用二级联动的话,我只能讲district一项隐藏掉,感觉代码不整洁
可以配置使得 get 得到 id 而不是名称吗?
选了省之后,市和区是自动选择的,如何去的这个特性?
项目使用vue2, 注册插件,
Vue.use(RegionPicker, { region: CHINA_REGION, vueVersion: 2 });
使用并设置初始值
<region-picker
:province="params.recvProvince"
:city="params.recvCity"
:district="params.recvArea"
@onchange="getRecvRegion">
</region-picker>
***
params: {
recvProvince: '福建省',
recvCity: '厦门市',
recvArea: '思明区',
}
最后页面中无法显示已设置的值,显示的是"请选择",
而在页面select里则有<select value="350000,福建省" class="province-select">
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "province"
在微信端,当选择天津或重庆的郊县时,第三级地区没有数据
1. 换成用 rollup
2. 兼容 vue1 和 vue2
[Vuewarn]: Property or method "change" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
但是定义了change这个方法,就无法实现这个插件本身的方法了。。
我也在做一个三级联动的组件,遇到一个问题。就是给3级联动组件根据给定值进行初始化的问题。
比如你这个省市区三级联动,如果我给省市区3个值分别一个值对其进行初始化。那么这3个值会传入组件并先后赋给3个select,假设我先给省赋值,再给市复制,再给区复制,那么问题就来了,给省复制给触发联动的逻辑,省改变会取清空市和区的值。。。。。
所以您是如何解决这个问题的呢?看了代码,没整明白
里面的select这么修改样式?我在style里面写入select样式,无效。是不是select是后面渲染出来的问题?
Uncaught TypeError: Cannot read property 'indexOf' of undefined
at VueComponent._searchIndex (eval at <anonymous> (app.js:2514), <anonymous>:1:3097)
at VueComponent.boundFn [as _searchIndex] (eval at <anonymous> (app.js:600), <anonymous>:125:14)
at VueComponent._selected (eval at <anonymous> (app.js:2514), <anonymous>:1:3249)
at VueComponent.boundFn [as _selected] (eval at <anonymous> (app.js:600), <anonymous>:125:14)
at VueComponent.get (eval at <anonymous> (app.js:2514), <anonymous>:1:3888)
at Watcher.get (eval at <anonymous> (app.js:600), <anonymous>:2934:27)
at Watcher.evaluate (eval at <anonymous> (app.js:600), <anonymous>:3042:21)
at VueComponent.computedGetter [as citySelected] (eval at <anonymous> (app.js:600), <anonymous>:3240:15)
at VueComponent.change (eval at <anonymous> (app.js:2514), <anonymous>:1:2854)
at Proxy.boundFn (eval at <anonymous> (app.js:600), <anonymous>:125:14)
_searchIndex @ app.js?016e:1
boundFn @ vue.common.js?caed:125
_selected @ app.js?016e:1
boundFn @ vue.common.js?caed:125
get @ app.js?016e:1
get @ vue.common.js?caed:2934
evaluate @ vue.common.js?caed:3042
computedGetter @ vue.common.js?caed:3240
change @ app.js?016e:1
boundFn @ vue.common.js?caed:125
change @ VM1594:2
invoker @ vue.common.js?caed:1944
vue.common.js?caed:521 [Vue warn]: Error when rendering component <RegionPicker>:
warn @ vue.common.js?caed:521
Vue._render @ vue.common.js?caed:2223
updateComponent @ vue.common.js?caed:2609
get @ vue.common.js?caed:2934
run @ vue.common.js?caed:3003
flushSchedulerQueue @ vue.common.js?caed:2807
(anonymous) @ vue.common.js?caed:473
nextTickHandler @ vue.common.js?caed:422
vue.common.js?caed:435 TypeError: Cannot read property 'indexOf' of undefined
at VueComponent._searchIndex (eval at <anonymous> (app.js:2514), <anonymous>:1:3097)
at VueComponent.boundFn [as _searchIndex] (eval at <anonymous> (app.js:600), <anonymous>:125:14)
at VueComponent._selected (eval at <anonymous> (app.js:2514), <anonymous>:1:3249)
at VueComponent.boundFn [as _selected] (eval at <anonymous> (app.js:600), <anonymous>:125:14)
at VueComponent.get (eval at <anonymous> (app.js:2514), <anonymous>:1:3888)
at Watcher.get (eval at <anonymous> (app.js:600), <anonymous>:2934:27)
at Watcher.evaluate (eval at <anonymous> (app.js:600), <anonymous>:3042:21)
at Proxy.computedGetter (eval at <anonymous> (app.js:600), <anonymous>:3240:15)
at Proxy.eval (eval at makeFunction (eval at <anonymous> (app.js:600)), <anonymous>:2:829)
at VueComponent.Vue._render (eval at <anonymous> (app.js:600), <anonymous>:2216:22)
logError @ vue.common.js?caed:435
app.js?016e:1 Uncaught TypeError: Cannot read property 'indexOf' of undefined
at VueComponent._searchIndex (eval at <anonymous> (app.js:2514), <anonymous>:1:3097)
at VueComponent.boundFn [as _searchIndex] (eval at <anonymous> (app.js:600), <anonymous>:125:14)
at VueComponent._selected (eval at <anonymous> (app.js:2514), <anonymous>:1:3249)
at VueComponent.boundFn [as _selected] (eval at <anonymous> (app.js:600), <anonymous>:125:14)
at VueComponent.get (eval at <anonymous> (app.js:2514), <anonymous>:1:4084)
at Watcher.get (eval at <anonymous> (app.js:600), <anonymous>:2934:27)
at Watcher.evaluate (eval at <anonymous> (app.js:600), <anonymous>:3042:21)
at VueComponent.computedGetter [as districtSelected] (eval at <anonymous> (app.js:600), <anonymous>:3240:15)
at VueComponent.change (eval at <anonymous> (app.js:2514), <anonymous>:1:2884)
at Proxy.boundFn (eval at <anonymous> (app.js:600), <anonymous>:125:14)
import Vue from 'vue'
import RegionPicker from 'vue-region-picker'
import REGION_DATA from 'vue-region-picker/data'
Vue.use(RegionPicker, {
region: REGION_DATA
})
// or
RegionPicker.region = REGION_DATA
new Vue({
components: { RegionPicker }
})
[Vue warn]: You are using the runtime-only build of Vue where the template option is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
(found in component <RegionPicker>)
比如:北京 -> 北京市郊县 ,然后第三级没有了
:completed="true"的时候,将province/city/distirct 设置成省市名字还是code,还是数组[code,name],都没法设置初始值,vuejs和此插件都是最新版本.
elementUI里有自己的select
标签实现,如何融入进去使用?
原来的组件引用的方式不变,支持通过插件的方式注册
import Vue from 'vue'
import VueRegionPicker from 'vue-region-picker'
import RegionData from 'vue-region-picker/data'
Vue.use(VueRegionPicker, {
data: RegionData
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.