晚上好,追个剧吧! 游客
image
YzmCMS建站教程-进阶篇

Vue版省市联动 json格式文字版本 (element组件)

vue版本引入组件js 上传 json格式文件演示图数据提交实例父级组件<script > const app = Vue.createApp({ data(){ return { data:{ ...

描述

vue版本

引入组件js 上传 json格式文件

image.png

演示图

image.png

数据提交

image.png

实例

父级组件

<script >
 const app = Vue.createApp({
        data(){
         return {
             data:{
              
            }
        },
        mounted(){
        },
        
        methods:{
            citys(value){
                this.data.city = value
            },
           
          },
     }).use(ElementPlus)
    app.component('shengshiqu',shengshiqu)
    app.mount('#add-app');
 </script>

安装组件

use(ElementPlus)

安装联动组件

app.component('shengshiqu',shengshiqu)

挂载实例

app.mount('#app');

子组件

const shengshiqu = ('shengshiqu', {
	template: `
	<el-cascader :props="checkstrictly" @change="change" filterable style="width:100%" v-model="optiondata" clearable :options="addressOptions" cle></el-cascader>
	`
	,
	props: {
        type:{
            type:Number,
        },
		treeoption:{
			type:Array,
		},
		checkstrictly:{
			type:Object,
		},
		is_clear:{
            type:Boolean,
            default:false
        },
    },
	watch:{
		is_clear(val){
			if(val){
				this.addressOptions = []
			}
		}
	},
	data(){
		return{
			optiondata:this.treeoption,
			addressOptions:[],
		}
	},
	mounted(){
		this.init()
	},
    methods: {
        init(){
			var url
			if(this.type == 1){
				url = '/public/static/js/shengshiqu/city-data-level3.json'
			}else if(this.type == 2){
				url ='/public/static/js/shengshiqu/city-data-level2.json'
			}else if(this.type == 3){
				url = '/public/static/js/shengshiqu/city-data-level1.json'
			}
			axios.get(url).then(response => {
			   this.addressOptions = response.data
			})
		},
		change(val){
			this.$emit('city',val)
		}
    },
});

把值传回父级组件

this.$emit('city',val)

父级接收值

this.data.city = value
0
收藏
海报

评论

请登录后发表评论

登录

评论列表 0

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

  • 友情链接: 黑猫查查网 黑猫图床 YzmCMS官方网站

    黑猫查查网是中立、开放和人性化的精选信息资源分享平台,查你所需,知你所想。

    站点声明: 本站资源仅供研究学习请勿商用以及产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系

    鄂ICP备2023011183号-2 · 鄂公网安备42282602000148