父组件调用子组件

<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. 我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration

    现在大部分的Spring项目都采用了基于注解的配置,采用了@Configuration 替换标签的做法.一行简单的注解就可以解决很多事情.但是,其实每一个注解背后都有很多值得学习和思考的内容.这些思考 ...

  2. Django框架简介,wsgiref 与 jinja2 模块

    目录 框架简介 wsgiref模块 jinja2 模块 框架简介 Django是一个web开发框架,用来开发web应用,本质就是, web框架+socket服务端 MVC框架和MTV框架 MVC,全名 ...

  3. IOS正则表达式 (身份证、电话、汉字等常用条件筛选)

    下面的正则列表   替换对应的正则规则 那个字符串就可以了  例如: //正则规则 NSString *regex = @"^((13[0-9])|(147)|(17[0-9])|(15[^ ...

  4. IMG 的alt和title的区别(转自 百度空间--路云的世界)

    图片标签img中alt与title的区别 图片标签img中alt与title的区别 可能很多新手在做站内优化的时候,不明白图片标签img中alt与title的区别,今天为大家说一下其中的区别. 大家可 ...

  5. AKOJ-2037-出行方案

    链接:https://oj.ahstu.cc/JudgeOnline/problem.php?id=2037 题意: 安科的夏天真是不一般的热,避免炎热,伍学长因此想为自己规划一个校园出行方案,使得从 ...

  6. js操作表格

    js 操作table: insertRow(),deleteRow(),insertCell(),deleteCell()方法 表格有几行: var trCnt = table.rows.length ...

  7. 牛客网Java刷题知识点之调用线程类的start()方法和run()方法的区别

    不多说,直接上干货! 前期博客 牛客网Java刷题知识点之四种不同的方式创建线程 这里很简单 首先,系统通过调用线程类的start()方法来启动一个线程,此时这个线程处于就绪状态,而非运行状态,也就意 ...

  8. 本地连接远程Oracle数据库

    由于项目开发测试,需要在本地连接远程的Oracle数据库 之前搭过环境,但是重装了系统,现在又重新装一遍 软件安装 连接远程Oracle需要两个软件: 一个Oracle客户端,instantclien ...

  9. 我的NopCommerce之旅(2): 系统环境及技术分析

    一.系统环境 IIS7.0 or above ASP.NET 4.5(MVC 5.0) .NET Framework 4.5.1 or above VS 2012 or above 二.架构设计 Pl ...

  10. jQuery属性和样式操作

    回顾 1. jquery基本使用 <script src="jquery.min.js"></script><script> $(functio ...