<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div class="" id="app">
<my-post title="my-post" @text="text"></my-post>
</div>
<script>
Vue.component('my-post',{
props:['title'],
template:`<div>
<div>{{title}}</div>
<button @click="btnClick">fff</button>
</div>`,
// <button @click="$emit('text')">fff</button>
methods:{
btnClick:function(){
this.$emit('text',1)
}
}
})
var vm = new Vue({
el:'#app',
data:{
msg:''
},
methods:{
text:function(x){
console.log('text',x)
}
}
})
</script>
</body>
</html>
vue 子组件调用父组件方法
最新推荐文章于 2022-04-02 14:19:16 发布