<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>子组件向父组件传递数据</title>
<script src="../vue.js"></script>
</head>
<body>
<div id="app">
<son @connect="say"></son>
</div>
</body>
</html>
<script>
Vue.component('son', {
template: `<button @click="send">点击</button>`,
methods: {
send() {
this.$emit('connect','子组件的数据')
}
}
});
let vm = new Vue({
el: '#app',
methods: {
say(arg) {
console.log(arg);
console.log('监听到了connect的触发')
}
}
})
</script>
vue 子组件向父组件传递数据
最新推荐文章于 2024-10-08 21:16:55 发布