父子组件间的数据传递_ref的问题
来源:4-2 父子组件间的数据传递
目訫
2019-04-27
<!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">
<script src="vue_expansion.js"></script>
<title>Props</title>
</head>
<body>
<div id="app">
<counter ref="one" :count="0"></counter>
<counter ref="two" :count="1"></counter>
<div>{{ total }}</div>
</div>
<script>
var counter = {
template: '<div @click="handleClick">{{ number }}</div>',
props: ['count'],
data () {
return {
number: this.count
}
},
methods: {
handleClick () {
this.number++
}
}
}
var vm = new Vue({
el: '#app',
computed: {
total () {
console.log(this.$refs.one)
// this.$refs.one.innerText + this.$refs.two.innerText
}
},
components: {
counter
}
})
</script>
</body>
</html>
老师,为什么找不到ref
写回答
1回答
-
ref不能作为computed计算属性的内容,它是dom节点不是纯数据
022019-04-29
相似问题