javascript - 如何将输入值数据传递给Vue中的根元素?
问题描述
我想在Vue中实现从组件到根元素的数据传输。我正在尝试使用方法从根元素访问“标题”值。执行代码时,控制台会抛出“未定义”而不是“标题”值。我的想法甚至可能吗?
var app = Vue.createApp({
props: ['handle'],
components: ['custom-form'],
methods: {
showData: function() {
console.log (this.handle)
return this.handle
}
},
created() {
console.log (this.showData())
}
})
app.component ('custom-form', {
props: ['value'],
template: `
<h1>{{title}}</h1>
<input type="text" v-model="inputValue" />
`,
data(){
return {
title: 'login'
}
},
computed:{
inputValue:{
get(){ this.title },
set(v){ this.$emit('update:inputValue',v) }
}
},
methods: {
handle(){
return this.inputValue
}
}
})
app.mount('#app')
解决方案
推荐阅读
- c++ - 类没有找到命名空间
- c++ - 内置方法如何在 C++ 中的一对优先级队列中成对工作?
- python - Python 字典不允许更改大小,但列表可以?
- javascript - 如何将数据推送到 vue 实例
- python - 尝试使用字典理解来保存用户输入
- python - 如何在 if 语句中向用户提出多个问题?
- java - 如何使用分页进行动态 Spring (Boot) JPA 查询?
- javascript - 如何使用反应返回路由内的组件(包括布尔方法、映射等)
- powershell - PowerShell浮点精度 - 提取实数的小数部分
- class - 将 BEM 类添加到 html TAG