欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue實現(xiàn)省市區(qū)級聯(lián)下拉選擇框

 更新時間:2022年03月04日 11:41:28   作者:theMuseCatcher  
這篇文章主要為大家詳細介紹了Vue實現(xiàn)省市區(qū)級聯(lián)下拉選擇框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue實現(xiàn)省市區(qū)級聯(lián)下拉選擇框的具體代碼,供大家參考,具體內(nèi)容如下

(Vue下拉選擇框Select組件二)為基礎(chǔ)實現(xiàn)省市區(qū)級聯(lián)下拉選擇框組件

(業(yè)務(wù)需要,固定省份選擇為貴州,沒有此業(yè)務(wù),不傳disabled屬性即可)

效果圖如下:

 ①創(chuàng)建級聯(lián)下拉選擇Cascader.vue組件

<template>
? <div class="m-cascader-wrap">
? ? <Select
? ? ? class="mr10"
? ? ? :style="`z-index: ${zIndex};`"
? ? ? mode="region"
? ? ? :disabled="true"
? ? ? :selectData="provinceData"
? ? ? :selValue="address.province"
? ? ? :width="84"
? ? ? placeholder="請選擇省"
? ? ? @getValue="getProvinceCode" />
? ? <Select
? ? ? class="mr10"
? ? ? :style="`z-index: ${zIndex};`"
? ? ? mode="region"
? ? ? :selectData="cityData"
? ? ? :selValue="address.city"
? ? ? :width="172"
? ? ? placeholder="請選擇市"
? ? ? @getValue="getCityCode" />
? ? <Select
? ? ? mode="region"
? ? ? :style="`z-index: ${zIndex};`"
? ? ? :selectData="areaData"
? ? ? :selValue="address.area"
? ? ? :width="172"
? ? ? placeholder="請選擇區(qū)"
? ? ? @getValue="getAreaCode" />
? </div>
</template>
<script>
import Select from '@/components/Select'
import { dictByType } from '@/api/index'
export default {
? name: 'Cascader',
? components: {
? ? Select
? },
? props: {
? ? selectedAddress: { // 省市區(qū)初始值
? ? ? type: Object,
? ? ? default: () => {
? ? ? ? return {}
? ? ? }
? ? },
? ? zIndex: {
? ? ? type: Number,
? ? ? default: 1
? ? }
? },
? data () {
? ? return {
? ? ? provinceData: [
? ? ? ? {
? ? ? ? ? dictVal: '貴州省',
? ? ? ? ? dictKey: 'P29'
? ? ? ? }
? ? ? ],
? ? ? cityData: [],
? ? ? areaData: [],
? ? ? regionParams: {
? ? ? ? type: '1',
? ? ? ? parentDictKey: ''
? ? ? },
? ? ? address: {
? ? ? ? province: 'P29',
? ? ? ? city: this.selectedAddress.city || '',
? ? ? ? area: this.selectedAddress.area || ''
? ? ? },
? ? ? addressName: {
? ? ? ? provinceName: '貴州省',
? ? ? ? cityName: '',
? ? ? ? areaName: ''
? ? ? },
? ? ? initialCity: true
? ? }
? },
? created () {
? ? this.getCity('P29')
? ? console.log('address:', this.address)
? },
? methods: {
? ? getCity (key) { // 獲取市數(shù)據(jù)
? ? ? this.regionParams.parentDictKey = key
? ? ? dictByType(this.regionParams).then(res => {
? ? ? ? console.log('city-res:', res)
? ? ? ? if (res.message.code === 0) {
? ? ? ? ? if (res.data.dataList) {
? ? ? ? ? ? this.cityData = res.data.dataList
? ? ? ? ? ? if (this.initialCity && this.address.city) {
? ? ? ? ? ? ? this.initialCity = false
? ? ? ? ? ? ? this.cityData.forEach(item => {
? ? ? ? ? ? ? ? if (item.dictKey === this.address.city) {
? ? ? ? ? ? ? ? ? this.getArea(item.dictKey)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? })
? ? ? ? ? ? }
? ? ? ? ? ? console.log('cityData:', this.cityData)
? ? ? ? ? }
? ? ? ? }
? ? ? })
? ? },
? ? getArea (key) { // 獲取區(qū)數(shù)據(jù)
? ? ? this.regionParams.parentDictKey = key
? ? ? dictByType(this.regionParams).then(res => {
? ? ? ? console.log('area-res:', res)
? ? ? ? if (res.message.code === 0) {
? ? ? ? ? if (res.data.dataList) {
? ? ? ? ? ? this.areaData = res.data.dataList
? ? ? ? ? ? console.log('areaData:', this.areaData)
? ? ? ? ? }
? ? ? ? }
? ? ? })
? ? },
? ? getProvinceCode (name, key) {
? ? ? console.log('province:', name, key)
? ? },
? ? getCityCode (name, key) {
? ? ? console.log('city:', name, key)
? ? ? this.address.city = key
? ? ? this.addressName.cityName = name
? ? ? this.$emit('getAddress', {}, {})
? ? ? // 獲取區(qū)下拉列表
? ? ? this.getArea(key)
? ? },
? ? getAreaCode (name, key) {
? ? ? console.log('area:', name, key)
? ? ? this.address.area = key
? ? ? this.addressName.areaName = name
? ? ? this.$emit('getAddress', this.address, this.addressName)
? ? }
? }
}
</script>
<style lang="less" scoped>
.m-cascader-wrap {
? display: inline-block;
? width: 449px;
? height: 40px;
? line-height: 40px;
}
</style>

②在要使用的頁面引入:

<Cascader
? :selectedAddress="register"
? mode="region"
? :zIndex="997"
? @getAddress="getRegisterAddress" />
import Cascader from '@/components/Cascader'
components: {
? ? Cascader
},
data () {
? return {
? ? register: {
? ? ? province: this.data.registerProvinceCode,
? ? ? city: this.data.registerCityCode,
? ? ? area: this.data.registerAreaCode
? ? } || {},
? }
}
methods: {
? getRegisterAddress (address, addressName) {
? ? console.log('register-address:', address)
? ? this.register = address
? ? if (JSON.stringify(addressName) !== '{}') { // 用于提交表單
? ? ? this.addParams.registerProvinceName = addressName.provinceName
? ? ? this.addParams.registerCityName = addressName.cityName
? ? ? this.addParams.registerAreaName = addressName.areaName
? ? }
? ? if (JSON.stringify(address) !== '{}') { // 用于校驗下拉表單是否未選擇
? ? ? this.checkFocus('register')
? ? }
? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue.js結(jié)合Ueditor富文本編輯器的實例代碼

    Vue.js結(jié)合Ueditor富文本編輯器的實例代碼

    本篇文章主要介紹了Vue.js結(jié)合Ueditor的項目實例代碼,這里整理了詳細的代碼,具有一定的參考價值,有興趣的可以了解一下
    2017-07-07
  • 一文詳解Pinia和Vuex與兩個Vue狀態(tài)管理模式

    一文詳解Pinia和Vuex與兩個Vue狀態(tài)管理模式

    這篇文章主要介紹了一文詳解Pinia和Vuex與兩個Vue狀態(tài)管理模式,Pinia和Vuex一樣都是是vue的全局狀態(tài)管理器。其實Pinia就是Vuex5,只不過為了尊重原作者的貢獻就沿用了這個看起來很甜的名字Pinia
    2022-08-08
  • 在Vue中實現(xiàn)父組件控制子組件的值的兩種方法

    在Vue中實現(xiàn)父組件控制子組件的值的兩種方法

    在Vue開發(fā)中,父組件和子組件之間的數(shù)據(jù)傳遞是一項常見的任務(wù),本文將介紹如何在Vue中實現(xiàn)父組件控制子組件的值,以便靈活地管理和更新子組件的數(shù)據(jù),文中有詳細的代碼講解,需要的朋友可以參考下
    2023-11-11
  • Vue實現(xiàn)搜索 和新聞列表功能簡單范例

    Vue實現(xiàn)搜索 和新聞列表功能簡單范例

    本文通過實例代碼給大家介紹了Vue實現(xiàn)搜索 和新聞列表功能簡單范例,非常不錯,具有參考借鑒價值,感興趣的朋友一起看看吧
    2018-03-03
  • Vue實現(xiàn)頁面的局部刷新(router-view頁面刷新)

    Vue實現(xiàn)頁面的局部刷新(router-view頁面刷新)

    本文主要介紹了Vue實現(xiàn)頁面的局部刷新(router-view頁面刷新),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • Vue3+Element Plus實現(xiàn)自定義彈窗組件的全屏功能

    Vue3+Element Plus實現(xiàn)自定義彈窗組件的全屏功能

    在現(xiàn)代化的前端開發(fā)中,彈窗組件是提升用戶體驗的重要元素,本文將介紹如何使用 Vue 3 和 Element Plus 庫來創(chuàng)建一個具有全屏功能的自定義彈窗組件,文中通過代碼示例講解的非常詳細,需要的朋友可以參考下
    2024-07-07
  • vue 將頁面公用的頭部組件化的方法

    vue 將頁面公用的頭部組件化的方法

    本篇文章主要介紹了vue 將頁面公用的頭部組件化的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Vue3計算屬性和異步計算屬性方式

    Vue3計算屬性和異步計算屬性方式

    這篇文章主要介紹了Vue3計算屬性和異步計算屬性方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue3如何避免樣式污染的方法示例

    vue3如何避免樣式污染的方法示例

    本文主要介紹了vue3如何避免樣式污染的方法示例,使用scoped可以避免父組件的樣式滲透到子組件中,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2024-09-09
  • vue移動端裁剪圖片結(jié)合插件Cropper的使用實例代碼

    vue移動端裁剪圖片結(jié)合插件Cropper的使用實例代碼

    本篇文章主要介紹了vue移動端裁剪圖片結(jié)合插件Cropper的使用實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07

最新評論