父组件调用子组件

<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. Codevs 1099 字串变换

    1099 字串变换 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 已知有 ...

  2. jzoj5991. 【北大2019冬令营模拟2019.1.6】Juice

    题面 题解 好迷-- //minamoto #include<bits/stdc++.h> #define R register #define ll long long #define ...

  3. Ajax登陆,使用Spring Security缓存跳转到登陆前的链接

    Spring Security缓存的应用之登陆后跳转到登录前源地址 什么意思? 用户访问网站,打开了一个链接:(origin url)起源链接 请求发送给服务器,服务器判断用户请求了受保护的资源. 由 ...

  4. JMeter博客系列:JMeter BeanShell示例

    1.简介 Apache JMeter是一个基于Java的开源工具,使您可以在应用程序上执行功能,负载,性能和回归测试.应用程序可以在Web服务器上运行,也可以是独立的.它支持在包含静态和动态资源的客户 ...

  5. AKOJ-1265-输出二叉树

    链接:https://oj.ahstu.cc/JudgeOnline/problem.php?id=1265 题意: 我们知道二叉树的先序序列和中序序列或者是中序和后序能够唯一确定一颗二叉树.现在给一 ...

  6. BZOJ1102(搜索)

    随便写一下的搜索,别的OJ深搜就过了,强大的BZOJ成功栈溢出RE了我并使我屈服地用广搜过掉,第一行手动开栈惨遭无视. 广搜: #pragma comment(linker, "/STACK ...

  7. ViewPager的使用总结

    这两天公司项目一直需要用到ViewPager来显示各式各样的Banner图,因而再次做了一些总结,不全后续应该还会更新的. 1.ViewPager要想做到一个界面显示多个items 有两种方式 ,一种 ...

  8. 我的NopCommerce之旅(8): 路由分析

    一.导图和基础介绍 本文主要介绍NopCommerce的路由机制,网上有一篇不错的文章,有兴趣的可以看看NopCommerce源码架构详解--对seo友好Url的路由机制实现源码分析 SEO,Sear ...

  9. (AOP)理解

    AOP的全称: Aspact  Oriented  Programming AOP的目标(作用):让我们可以“专心做事”  日志记录,事务处理,异常捕获,缓存操作. AOP原理 将复杂的需求分解出不同 ...

  10. linux学习笔记汇总

    linux 文件系统是采用级层树状的目录结构,采用"/"根目录的方式 目录结构: / 根目录           |---root: 存放root用户相关的文件          ...