父组件调用子组件

<Cselect ref="registerAddress"></Cselect>

import Cselect from '../../../../components/common/select'

export default {

Cselect

}

父组件页面通过 this.registeraddress就可以获取子组件页面的数据

子组件

<template>
<div>
<el-select v-model="prov" style="width:167px;margin-right: 25px;">
<el-option v-for="option in arr" :value="option.name">
{{ option.name }}
</el-option>
</el-select>
<el-select v-model="city" style="width:167px;margin-right: 25px;">
<el-option v-for="option in cityArr" :value="option.name">
{{ option.name }}
</el-option>
</el-select>
<el-select v-model="district" v-if="district" style="width:167px;">
<el-option v-for="option in districtArr" :value="option.name">
{{ option.name }}
</el-option>
</el-select>
</div>
</template>
<script>
import area from './area.js'
export default {
name: 'Cselect',
data() {
return {
arr: area.arrAll,
prov: '省份',
city: '城市',
district: '区域',
cityArr: [],
districtArr: [],
}
},
methods: {
updateCity: function() {
for (var i in this.arr) {
var obj = this.arr[i];
if (obj.name) {
if (obj.name == this.prov) {
this.cityArr = obj.sub;
break;
}
}
}
this.city = this.cityArr[1].name;
},
updateDistrict: function() {
for (var i in this.cityArr) {
var obj = this.cityArr[i];
if (obj.name == this.city) {
this.districtArr = obj.sub;
break;
}
}
if (this.districtArr && this.districtArr.length > 0 && this.districtArr[1].name) {
this.district = this.districtArr[1].name;
} else {
this.district = '';
}
}
},
beforeMount() {
this.updateCity();
this.updateDistrict();

},
watch: {

prov: function() {
this.updateCity();
this.updateDistrict();
},
city: function() {
this.updateDistrict();
}
}

}
</script>

vue父组件获取子组件页面的数组 以城市三级联动为例的更多相关文章

  1. 关于Vue中,父组件获取子组件的数据(子组件调用父组件函数)的方法

    1. 父组件调用子组件时,在调用处传给子组件一个方法 :on-update="updateData"   2. 子组件在props中,接收这个方法并声明 props: { onUp ...

  2. 子组件获取父组件数据 propsDown, 父组件获取子组件数据 eventUp

    (一) popsDowm 三种方法获取父组件数据:被动获得(1):主动获取(2). 1.被动获得: 父组件:v-bind: 绑定变量参数和方法参数:子组件:props 接收参数.可以在模板中直接使用也 ...

  3. Vee-validate 父组件获取子组件表单校验结果

    vee-validate 是为 Vue.js 量身打造的表单校验框架,允许您校验输入的内容并显示对应的错误提示信息.它内置了很多常见的校验规则,可以组合使用多种校验规则,大部分场景只需要配置就能实现开 ...

  4. Angular5 父组件获取子组件实例( ViewChildren、ViewChild用法)

    原文链接 Understanding ViewChildren, ContentChildren, and QueryList in Angular 使用场景 有时候,我们想要在父组件中访问它的子组件 ...

  5. React Hook父组件获取子组件的数据/函数

    我们知道在react中,常用props实现子组件数据到父组件的传递,但是父组件调用子组件的功能却不常用.文档上说ref其实不是最佳的选择,但是想着偷懒不学redux,在网上找了很多教程,要不就是hoo ...

  6. antd 父组件获取子组件中form表单的值

    还是拿代码来讲吧,详情见注释 子组件 import React, { Component } from 'react'; import { Form, Input } from 'antd'; con ...

  7. vue 的父组件和子组件互相获取数据和方法

    父组件主动获取子组件的数据和方法 一.ref(但不能实时更新获取) 1.调用子组件的时候 定义一个ref <child ref="headerChild"></c ...

  8. vue:父子组件间通信,父组件调用子组件方法进行校验子组件的表单

    参考: ElementUI多个子组件表单的校验管理:https://www.jianshu.com/p/541d8b18cf95 Vue 子组件调用父组件方法总结:https://juejin.im/ ...

  9. vue3 template refs dom的引用、组件的引用、获取子组件的值

    介绍 通过 ref() 还可以引用页面上的元素或组件. DOM 的引用 <template> <div> <h3 ref="h3Ref">Tem ...

随机推荐

  1. StringUtils中常用方法leftPad(),rightPad(),center()

    org.apache.commons.lang3的StringUtils 方法如下: public static String leftPadTime(Integer time){    return ...

  2. html中id name class的区别(转)

    HTML 中 id与name 区别 一个name可以同时对应多个控件,比如checkbox和radio 而id必须是全文档中唯一的 id的用途 1) id是HTML元素的Identity,主要是在客户 ...

  3. noip2017普及组

    过了这么久才来写博客,也是我这么一段时间都很低迷吧.... 老实来说,今年应该是要打提高组的...可还是打了普及组... 其实最猥琐的还是我连普及都写挂了,作为一个学了两年的人,图论,进阶dp都写过的 ...

  4. hibernate错误总结1

  5. 为GitHub项目添加协议

    解决方法 如果一开始在GitHub上创建仓库时没有添加协议,可以用以下方式来重新添加相关的协议: 打开GitHub上的某个仓库,点击Create new file: 在新建文件的页面上,输入文件名LI ...

  6. Image.resize()和Image.thumbnail()的区别

    Image.resize()和Image.thumbnail()的区别 根据代码和代码注释, 这两个函数都是对图片进行缩放, 两者的主要区别如下: resize()函数会返回一个Image对象, th ...

  7. PostgreSQL-7-数据连接

    1.通过WHERE进行简单连接 SELECT * FROM company3,department  不添加WHERE将会显示所有数据 SELECT * FROM company3,departmen ...

  8. STM32的低功耗模式

    一 待机模式standby和STOP模式的区别: 进入低功耗模式:都一样,都是先关闭相应时钟,关闭相应外设,配置相应所有IO口(浮动输入),然后配置相应的唤醒中断源,中断影响的O口,然后调用相应函数进 ...

  9. Ubuntu安装LAMP

    1.安装apache2 sudo apt-get install apache2 sudo apt-get install apache2 Apache安装成功后,/var/www/默认作为web的根 ...

  10. T4310 祖玛游戏

    题目描述 祖玛是一款曾经风靡全球的游戏,其玩法是:在一条轨道上初始排列着若干 个彩色珠子,其中任意三个相邻的珠子不会完全同色.此后,你可以发射珠子到 轨道上并加入原有序列中.一旦有三个或更多同色的珠子 ...