<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<button @click="changeMesg">点击将子组件的信息传到跟组件里</button>
<h1>{{mesg}}</h1>
<son ref="sonDom"></son>
</div>
</body>
<template id="son">
<div>
<h1>{{sonMesg}}</h1>
</div>
</template>
<script src="./vue.js"></script>
<script>
Vue.component('son', {
template: '#son',
data () {
return {
sonMesg: '子组件的信息'
}
}
})
const app = new Vue({
el:'#app',
data: {
mesg: '跟组件的信息'
},
methods: {
changeMesg () {
this.mesg = this.$refs.sonDom.sonMesg
}
}
})
</script>
</html>
通过this.$refs.[refName]来进行给父组件传递信息
猜你喜欢
转载自blog.csdn.net/qq_45802159/article/details/104296363
今日推荐
周排行