typescript - 使用 Vue.js 将文本数据从一个组件传递到另一个组件
问题描述
我在将文本数据从自定义组件传递到主组件时遇到问题。这个自定义组件是文本区域,我想将文本存储到我的数据库中。我尝试使用 Prop 注释,但没有用。当我 console.log(this.text) 我没有看到任何文本数据。我可能做错了,所以如果有人可以帮助我,那就太棒了!
我的主要组件
<template>
<div>
<textarea-component></textarea-component>
<button @click="save()"></button>
<div>
</template>
<script lang=ts>
import {Component, Prop, Vue} from 'vue-property-decorator';
import api from '@/infrastructure/api/noteApi';
@Component({
components: {
'textarea-component': TextAreaComponent,
},
})
export default class MainPage extends Vue {
@Prop
text!: string;
private async save() {
//check if the data is passing
console.log(this.text)
//save to the database
await api.saveText(string)
.then((Response) => {
console.log(Response)
});
}
}
</script>
<template>
<div>
<textarea v-bind:value="text">
</textarea>
</div>
</template>
<script lang=ts>
import {Component, Vue} from 'vue-property-decorator';
@Component
export default class TextAreaComponent extends Vue {
text:string = '';
}
</script>
解决方案
推荐阅读
- html - 对齐标签和输入标签
- mysql - 创建 SQL 视图
- ssms - 如何在 MySql 中从单元格中间提取单词?
- java - 提高 Alog 的效率(将数组向左旋转 n 次迭代)
- php - 将 WooCommerce 自定义帐号字段值限制为仅限数字
- java - Android:NullPointerException'double java.lang.Double.doubleValue()'
- python - 从 PDF 中识别不可选择的图像
- excel - 希望下面的代码等同于带有格式的 Vlookup。有什么建议么。Excel VBA
- unity3d - 使用放大着色器进行框边界的横截面着色器
- blazor - 我可以结合服务器和客户端模型吗?