vue数据传递二
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>父传子,方法传递</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src="vue/vue.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- 父组件向子组件传递方法
1、在父组件中创建方法或绑定函数
<button v-on:click='dianji'>我是父组件</button>
2、在子组件标签中<子组件标签 v-on:自定义接收名= '父组件方法名'>
<son v-on:parentdianji(自定义接收名) = 'dianji(父组件方法名)'></son>
3、在子组件模板中,创建绑定事件或其他,通过在函数中this.$emit('自定义接收名'),接收父组件方法
<button v-on:click='sonDianji'>我是子组件</button>
sonDianji:function(){
this.$emit('parentdianji')
}
-->
<div id="app">
<button v-on:click='dianji'>我是父组件</button>
<son v-on:parentdianji = 'dianji'></son>
</div>
<template id="son">
<button v-on:click='sonDianji'>我是子组件</button>
</template>
<script>
var son = {
data:function(){
return{
};
},
methods:{
sonDianji:function(){
this.$emit('parentdianji')
}
},
template:'#son',
};
var app = new Vue({
el:'#app',
data:{},
methods:{
dianji:function(){
alert('你好啊我是父组件')
}
},
computed:{
},
watch:{
},
components:{
'son':son,
}
})
</script>
</body>
</html>