前言
学习vue组件通信之props
提示:以下是本篇文章正文内容,下面案例可供参考
一.vue组件之通信
1. 概要
目的:要在子组件使用数据a,a的值来源于父组件
props:字符数组 -> props:[‘a’]
1.a是组件的属性
2.a的用法和data中数据用法一样
3.a的值来源于父组件
2.示例代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue组件之通信</title>
</head>
<body>
<div id="app">
<child-a a="200"></child-a>
</div>
</body>
</html>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script type="text/javascript">
Vue.component("child-a",{
template:"<button>我是子组件{{a}}</button>",
props:["a"]
});
new Vue({
el:"#app"
});
</script>
3.展示效果
总结
学习vue组件通信之props