


The mintui picker selector in vue realizes the second-level linkage of provinces and cities
This article mainly introduces the example of mintui picker selector in vue learning to realize the second-level linkage of provinces and cities. It is of great practical value. Friends in need can refer to it. I hope it can help everyone.
This article introduces the example of using the mintui picker selector in vue learning to realize the second-level linkage of provinces and cities. I would like to share it with you. The details are as follows:
Mint UI usage documentation: https://mint -ui.github.io/docs/#/zh-cn2
Popup popup box introduction: https://mint-ui.github.io/docs/#/zh-cn2/popup
Picker selector introduction: https://mint-ui.github.io/docs/#/zh-cn2/picker
Datetime picker date picker introduction: https://mint-ui.github.io/docs/#/zh-cn2/datetime-picker
The code is as follows:
<!-- 页面模版 --> <template> <p> <!--header--> <com-header :title="headerData.title" :toLink="headerData.toLink"></com-header> <!--header end--> <!--container--> <p class="ybb-yuyue"> <p class="yy-item-box mine-me"> <a class="mint-cell mint-field"> <p class="mint-cell-left"></p> <p class="mint-cell-wrapper"> <p class="mint-cell-title"> <span class="mint-cell-text">头像</span> </p> <p class="mint-cell-value"> <p class="mint-cell-value"></p> <img class="img-box5 lazy" src="/static/imghwm/default1.png" data-src="data.photo" v-bind: :onerror="headImg" alt="The mintui picker selector in vue realizes the second-level linkage of provinces and cities" > </p> </p> </a> </p> <p class="yy-item-box mine-me"> <a class="mint-cell mint-field"> <p class="mint-cell-left"></p> <p class="mint-cell-wrapper"> <p class="mint-cell-title"> <span class="mint-cell-text">姓名</span> </p> <p class="mint-cell-value"> <p class="mint-cell-value"> <input placeholder="请输入姓名" type="text" class="mint-field-core text-right" v-model="data.userName"> <p class="mint-field-clear" style="display: none;"><i class="mintui mintui-field-error"></i></p> </p> </p> </p> </a> <a class="mint-cell mint-field"> <p class="mint-cell-left"></p> <p class="mint-cell-wrapper"> <p class="mint-cell-title"> <span class="mint-cell-text">性别</span> </p> <p class="mint-cell-value"> <p class="mint-cell-value is-link" @click="sexVisible = true"> <input placeholder="请选择性别" type="text" class="mint-field-core text-right" readonly="readonly" v-model="data.sexText"> <p class="mint-field-clear" style="display: none;"><i class="mintui mintui-field-error"></i></p> </p> </p> <i class="mint-cell-allow-right"></i> <mt-actionsheet :actions="sexs" v-model="sexVisible" cancel-text="取消"></mt-actionsheet> </p> </a> <a class="mint-cell mint-field"> <p class="mint-cell-left"></p> <p class="mint-cell-wrapper"> <p class="mint-cell-title"> <span class="mint-cell-text">出生日期</span> </p> <p class="mint-cell-value"> <p class="mint-cell-value is-link" @click="open('datePicker')"> <input placeholder="请选择日期" type="text" class="mint-field-core text-right" readonly="readonly" v-model="data.birthday"> <p class="mint-field-clear" style="display: none;"><i class="mintui mintui-field-error"></i></p> </p> </p> <i class="mint-cell-allow-right"></i> <mt-datetime-picker ref="datePicker" type="date" :startDate="startDate" :endDate="endDate" v-model="dateValue" @confirm="handleChange"> </mt-datetime-picker> </p> </a> </p> <p class="yy-item-box mine-me"> <a class="mint-cell mint-field"> <p class="mint-cell-left"></p> <p class="mint-cell-wrapper"> <p class="mint-cell-title"> <span class="mint-cell-text">电话号码</span> </p> <p class="mint-cell-value"> <p class="mint-cell-value"> <input placeholder="请输入电话号码" type="text" readonly="readonly" class="mint-field-core text-right gray" v-model="data.mobile"> <p class="mint-field-clear" style="display: none;"><i class="mintui mintui-field-error"></i></p> </p> </p> </p> </a> <a class="mint-cell mint-field"> <p class="mint-cell-left"></p> <p class="mint-cell-wrapper"> <p class="mint-cell-title"> <span class="mint-cell-text">所在地区</span> </p> <p class="mint-cell-value"> <p class="mint-cell-value is-link" @click="choiceArea"> <input placeholder="请选择省市" type="text" class="mint-field-core text-right" readonly="readonly" v-model="data.areaText"> <p class="mint-field-clear" style="display: none;"><i class="mintui mintui-field-error"></i></p> </p> </p> <i class="mint-cell-allow-right"></i> <mt-popup v-model="popupVisible" position="bottom" class="mint-popup-4"> <p class="picker-toolbar"> <span class="mint-datetime-action mint-datetime-cancel" @click="cancleaddress">取消</span> <span class="mint-datetime-action mint-datetime-confirm" @click="selectaddress">确定</span> </p> <mt-picker :slots="citySlots" @change="onCityChange" :visible-item-count="3"></mt-picker> </mt-popup> </p> </a> <a class="mint-cell mint-field"> <p class="mint-cell-left"></p> <p class="mint-cell-wrapper"> <p class="mint-cell-title"> <span class="mint-cell-text">详细地址</span> </p> <p class="mint-cell-value"> <p class="mint-cell-value"> <input placeholder="街道、楼牌号等" type="text" class="mint-field-core text-right" v-model="data.address"> <p class="mint-field-clear" style="display: none;"><i class="mintui mintui-field-error"></i></p> </p> </p> </p> </a> </p> </p> <p class="yuyue-submit"> <button class="mint-button mint-button--default mint-button--large ybb-btn" @click="infoSave"><label class="mint-button-text title-1">保存</label></button> </p> <!--container end--> </p> </template> <script> import {Toast} from 'mint-ui' import validators from '../utils/validators' import comHeader from 'components/comHeader' import mineInfoService from 'SERVICES/mineInfoService' export default { components: { comHeader }, data: () => ({ headImg: 'this.src="' + require('../assets/img.png') + '"', headerData: { title: '我的资料', toLink: '/Mine' }, popupVisible: false, sexVisible: false, areaPicker: '', areaList: [], data: { photo: '', userName: '', sex: '', sexText: '', mobile: '', birthday: '', privinceName: '', provinceId: '', cityName: '', cityId: '', address: '', areaText: '' }, sexs: [], citySlots: [ { flex: 1, values: Object.keys(address), className: 'slot1', textAlign: 'center' }, { pider: true, content: '-', className: 'slot2' }, { flex: 1, values: Object.values(address)[0], className: 'slot3', textAlign: 'center' } ], addressProvince: '', addressProvinceId: '', addressCity: '', addressCityId: '', dateValue: new Date(), startDate: new Date('1900-01-01'), endDate: new Date() }), created () { this.loadMineInfo() this.loadAreaList() }, mounted () { this.sexs = [{ name: '男', method: this.selectMan }, { name: '女', method: this.selectWoman }] }, methods: { loadAreaList: function () { mineInfoService.loadAreaList().then(res => { if (res.t) { this.areaList = res.t address = this.areaList.areaList[0] provinceCodeList = this.areaList.provinceCodeList[0] cityCodeList = this.areaList.cityCodeList[0] this.citySlots[0].values = Object.keys(address) this.citySlots[2].values = Object.values(address)[0] } else { Toast('地区数据异常') } }) }, choiceArea: function () { this.popupVisible = true // 设置默认选中 if (this.data.privinceName !== '' && this.data.cityName !== '') { this.areaPicker.setSlotValue(0, this.data.privinceName) this.areaPicker.setSlotValue(1, this.data.cityName) console.log(this.data.privinceName + '-' + this.data.cityName) } }, cancleaddress: function () { this.popupVisible = false this.areaPicker.setSlotValue(0, this.data.privinceName) this.areaPicker.setSlotValue(1, this.data.cityName) }, selectaddress: function () { this.popupVisible = false this.data.privinceName = this.addressProvince this.data.cityName = this.addressCity this.data.provinceId = this.addressProvinceId this.data.cityId = this.addressCityId this.data.areaText = this.data.privinceName + this.data.cityName }, infoSave: function () { if (this.data.userName.trim() === '') { Toast('请输入姓名') } else if (this.data.userName.trim().length > 12) { Toast('姓名不能超过12个字符') } else if (this.data.sex.toString().trim() === '') { Toast('请选择性别') } else if (this.data.birthday.trim() === '') { Toast('请选择出生日期') } else if (this.data.mobile.trim() === '') { Toast('请输入电话号码') } else if (!validators.mobile(this.data.mobile.trim())) { Toast('电话号码不正确') } else if (this.data.areaText.toString().trim() === '') { Toast('请选择所在地区') } else if (this.data.address.trim() === '') { Toast('请输入详细地址') } else if (this.data.address.trim().length > 50) { Toast('详细地址不能超过50个字符') } else { this.doAdd() } }, doAdd: function () { mineInfoService.updateAccount(this.data).then(res => { Toast('修改成功') this.$router.push('/Mine') }) }, loadMineInfo: function () { mineInfoService.loadMineInfo().then(res => { this.data.photo = res.t.member.photo || '' this.data.userName = res.t.member.userName || '' this.data.sex = res.t.member.sex || '' this.data.sexText = res.t.member.sex === '1' ? '男' : (res.t.member.sex === '0' ? '女' : '') this.data.mobile = res.t.member.mobile || '' this.data.birthday = res.t.member.birthday || '' this.data.area = res.t.member.area || '' this.data.address = res.t.member.address || '' this.dateValue = this.data.birthday this.data.privinceName = res.t.member.priviceName || '' this.data.cityName = res.t.member.cityName || '' this.data.provinceId = res.t.member.provinceId || '' this.data.cityId = res.t.member.cityId || '' this.data.areaText = this.data.privinceName + this.data.cityName }) }, onCityChange: function (picker, values) { this.areaPicker = picker /* 此处不直接使用this.data.privinceName、this.data.cityName、this.data.provinceId、this.data.cityId,由于在加载地区信息之后,我又重新设置了绑定到slots属性的值,此时也会触发@change事件,所以在nCityChange方法里需要用四个变量替代上述四个变量来记录当前选中的值,然后在点击确定之后的方法里将这四个值赋给上述四个变量。如果直接在该方法里使用上述四个变量来获取当前选中的值,可能导致数据错乱 */ picker.setSlotValues(1, address[values[0]]) this.addressProvince = values[0] this.addressCity = values[1] this.addressProvinceId = provinceCodeList[this.addressProvince] + '' this.addressCityId = cityCodeList[this.addressCity] + '' }, open: function (picker) { this.dateValue = this.data.birthday this.$refs[picker].open() }, handleChange: function (value) { this.data.birthday = window.moment(value).format('YYYY-MM-DD') }, selectMan: function () { this.data.sex = '1' this.data.sexText = '男' }, selectWoman: function () { this.data.sex = '0' this.data.sexText = '女' } } } let address = {} let provinceCodeList = {} let cityCodeList = {} </script> <style scoped> .mint-popup-4 { width: 100%; } .mint-popup-4 .picker-slot-wrapper, .page-popup .mint-popup-4 .picker-item { -webkit-backface-visibility: hidden; backface-visibility: hidden; } </style>
The regional data format is as follows:
{ "code": 200, "msg": "获取区域信息成功!", "t": { "areaList": [ { "上海": [ "上海" ], "北京": [ "北京" ], "广东": [ "广州", "深圳" ], "江苏": [ "徐州", "南京" ], "福建": [ "福州" ] } ], "provinceCodeList": [ { "上海": [ "120001" ], "北京": [ "110001" ], "广东": [ "130001" ], "江苏": [ "130007" ], "福建": [ "0100" ] } ], "cityCodeList": [ { "上海": [ "120002" ], "北京": [ "110002" ], "广州": [ "130002" ], "南京": [ "130006" ], "深圳": [ "518000" ], "福州": [ "0200" ], "徐州": [ "130009" ] } ] } }
Related recommendations:
Detailed explanation of a self-made city and county secondary linkage component in Angular4
Ajax combined with php to achieve secondary linkage instance method
js implements Select secondary linkage instance sharing in HTML
The above is the detailed content of The mintui picker selector in vue realizes the second-level linkage of provinces and cities. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
