vue.js - 如何更改 v-textarea Vue.js 中的选定文本?
问题描述
我希望在单击按钮以更改 v 容器中的选定文本时调用一个函数,我该怎么做?我会很高兴任何信息
<template>
<div class="text">
<v-btn
@click="editText"
>
</v-btn>
<v-textarea
v-model="text"
></v-textarea>
</div>
</template>
<script>
export default {
name: "ArticleForm",
data() {
return {
text: 'some text',
}
},
methods: {
editText() {
... how?
}
}
}
</script>
<style scoped>
</style>
解决方案
您可以window.getSelection
用于选定的文本。这是演示
证监会:
<template>
<v-app>
<v-content>
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore facere
aspernatur explicabo voluptatibus? Non temporibus, dicta illum
perferendis error voluptatum. Rerum officiis debitis voluptas earum
nulla consequatur necessitatibus tenetur eius.
</div>
<v-btn class="my-5" @click="editText">Edit</v-btn>
<v-textarea v-model="text"></v-textarea>
</v-content>
</v-app>
</template>
<script>
export default {
name: "App",
data() {
return {
text: "",
};
},
methods: {
editText() {
if (window.getSelection) this.text = window.getSelection().toString();
},
},
};
</script>
推荐阅读
- node.js - 使用 Postman 发送数据时无法通过 resify 获取请求正文
- typescript - 我可以从联合类型派生值以创建新的联合类型吗?
- python - 如何将 TensorFlow 模型导出为 .tflite 文件?
- java - 如何在活动开始时以最短时间显示大图像?
- amazon-web-services - AWS 服务器和 Lambda 中的网络可用性 SLA
- r - R:从向量的增加部分中提取频率序列(列联表)
- java - 按字母顺序正确排序数组的问题
- c# - 开发 Unity 增强现实 vuforia 应用并与原生 android 应用集成
- c# - 如何在端口号 53135 中使用 IIS Express 运行 HTTPS
- java - 在 Java 中使用 ArcGIS 要素查询服务