每天一点点之vue框架开发 - vue组件之间传值(父向子传值)
路由文件
{
path: '/productListBase', name: 'productListLink', component: ProductListBase, redirect: '/productList', children: [
{
path: '/productList',
components: {
default: Banner,
product_list: ProductList
}
}
]
},
这个是中间文件(也就是父级)
<template>
<div class="product">
<router-view :aaa="aaa"></router-view>
<router-view name="product_list"></router-view>
</div>
</template> <script>
export default {
data(){
return {
aaa:{
name_en:'PRODUCT',
name_zh:'MIRROR产品'
}
}
}
}
</script>
在父级设置参数,如果是aaa='aaa',此时传的是aaa的字符串,而:aaa="aaa"传的是对象(或数组)
在子页面接收参数
export default {
props:['aaa'],
computed:{
my(){
this.banner = this.aaa
console.log(this.aaa,'aaa')
}
},
}
通过 props 来接收父级传过来的参数,然后在 使用computed属性将收到的值赋给当前组件的data中的banner。
最后要记得在子页面中调用 my() 方法
<template>
<div>
{{my}}
</div>
</template>
子组件向父组件传值
子组件
this.$emit("changes",);
父组件
<searchH ref="searchH" @changes="aaa()"></searchH>
methods:{
aaa(e){
console.log(e)
}
}
每天一点点之vue框架开发 - vue组件之间传值(父向子传值)的更多相关文章
- 每天一点点之vue框架开发 - vue坑-This relative module was not found
94% asset optimization ERROR Failed to compile with 1 errors This relative module was not found: * . ...
- 每天一点点之vue框架开发 - vue坑-input 的checked渲染问题
选中radio或者checkbox需要注意的是: 不管<input type='radio checked='true''> 你的checked属性值是true或者false,他都会选中 ...
- 每天一点点之vue框架开发 - vue 动态替换路由(地址栏)参数
import merge from 'webpack-merge': // 修改原有参数 this.$router.push({ query:merge(this.$route.query,{'max ...
- 每天一点点之vue框架开发 - vue中使用vue-router切换页面时自动滚动到顶部的方法
1. 在main.js入口文件中写入 //路由跳转后,页面回到顶部 router.afterEach(() => { document.body.scrollTop = 0; document. ...
- 每天一点点之vue框架开发 - 引入Jquery
1. 安装jquery npm install jquery --save-dev 2.在build/webpack.base.conf.js中添加如下内容 var webpack = require ...
- 每天一点点之vue框架开发 - 使用vue-router路由
1.安装路由(安装过的跳过此步) // 进入项目根目录 cd frontend // 安装 npm install vue-router --save-dev 2.在入口文件main.js中引入路由 ...
- Vue 框架-09-初识组件的应用
Vue 框架-09-初识组件的应用 今天的第一个小实例,初步使用组件: 在 app.js 中定义模板组件,在 html 文件中使用自定义标签来显示 js 文件中定义的 html 代码块 比如说,下面定 ...
- Vue框架:vue-cookies组件
目录 一.vue-cookies简介 二.vue-cookies安装与配置 三.vue-cookies的使用 一.vue-cookies简介 vue-cookies组件是vue框架用来操作浏览器coo ...
- Vue其他指令-组件-全局-局部-组件的交互父传子
v-once指令 once:一旦,当...时候 <!DOCTYPE html> <html lang="zh"> <head> <meta ...
随机推荐
- webpack 4 脚手架搭建
1.在cmd控制台安装环境 npm install express (这是一个本地服务器配置) 2.在src 文件夹下建 mian.js 和 express.js 两个jS文件
- Lesson 4 Seeing hands
How did vera discover she had this gift of second sight? Several cases have been reported in Russia ...
- js 中 一些重要的数组方法
今天在学Vue的时候,看到了好多JS的数组方法,但是我不知道,我以为是Vue的方法,结果找了半天资料也没找出来,最后才发现这是JS的数组对象方法,于是就想做一下笔记,加深一下印象. Array 对象方 ...
- Python面试2未完待续
Python面试重点(基础篇) 注意:只有必答题部分计算分值,补充题不计算分值. 第一部分 必答题(每题2分) 简述列举了解的编程语言及语言间的区别? c语言是编译型语言,运行速度快,但翻译时间长py ...
- 数据结构 c++ 广义表
// CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...
- vue :style 动态绑定style
<div class="right userPicture" :style="[{'background':`url(${userImg}) no-repeat c ...
- Linux-kernel-timeline
Linux kernel Protocol Location HTTP https://www.kernel.org/pub/ GIT https://git.kernel.org/ RSYNC rs ...
- 比较 CEILING 和 FLOOR
CEILING 函数返回大于或等于所给数字表达式的最小整数. FLOOR 函数返回小于或等于所给数字表达式的最大整数. 例如,对于数字表达式 12.9273,CEILING 将返回 13,FLOOR ...
- windows上使用git
开始的时候同事只给了一个地址,类似这样:git@111.111.1.1:ABCDEF (1)如何在Windows上使用Git 有一篇博客不错:http://www.tuicool.com/articl ...
- Spring AOP 管理事务
<aop:config proxy-target-class="true"> <aop:pointcut expression="execution(* ...