admin_vue/10-组件化开发/08-父子组件的访问/父组件访问子组件$ref.html

44 lines
986 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<apps ref="first"></apps>
<button @click="refClick()">点击我</button>
</div>
<template id="tpl">
<div>
<h1>{{content}}</h1>
</div>
</template>
</body>
<script src="../../../JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
methods: {
refClick(){
console.log(this.$refs.first.content);
this.$refs.first.content="这是被修改后的内容"
console.log(this.$refs.first.content);
}
},
components:{
'apps':{
template:"#tpl",
data(){
return{
content:"这是内容",
list:["这是第一条", "这是第二条", "这是第三条"]
}
}
}
}
})
</script>
</html>