响应式绑定<a-textarea>的内容

项目中的 <a-textarea>组件需要自动填入下方数据表的物品名称+数量+单位,效果如下:

尝试 <a-textarea>{{插值}}</a-textarea>,实现不了,问ai得知需要使用v-decorator 指令的initialValue 属性

问:

如何绑定数据到textarea内容中?

<a-textarea :rows="4" v-decorator="[ 'content', { rules: [{ required: true, message: '请输入名称!' }] } ]"/>

ai答:

对于 Ant Design Vue 中的 <a-textarea> 组件,正确的绑定数据的方式是使用 v-decorator 指令的 initialValue 属性。

<template><a-form :form="form"><a-form-item label="Content" :colon="false" :validate-status="getFieldError('content') ? 'error' : ''":help="getFieldError('content') || ''"><a-textarea :rows="4"v-decorator="['content', { initialValue: content, rules: [{ required: true, message: '请输入内容!' }] }]"></a-textarea></a-form-item><a-form-item><a-button type="primary" @click="submitForm">提交</a-button></a-form-item></a-form>
</template><script>
export default {data() {return {form: this.$form.createForm(this),content: '', // 数据属性用于绑定 <a-textarea> 的内容};},methods: {getFieldError(name) {const errors = this.form.getFieldError(name);if (errors && errors.length > 0) {return errors[0];} return '';},submitForm() {this.form.validateFields((errors, values) => {if (!errors) {// 表单验证通过,执行提交操作// ...}});},},
};
</script>

示例中,我们使用 initialValue 属性将 content 数据属性绑定到 <a-textarea> 的初始值上。这样,当页面加载时,<a-textarea> 的内容将会显示 content 的初始值。同时,当用户输入或修改 <a-textarea> 的内容时,content 的值也会相应地更新。

注意:initialValue表示初始值,如果用户不编辑<a-textarea> 的内容,绑定内容将一直跟随改变,一旦对<a-textarea> 的内容进行了编辑,内容就不再跟随绑定变量改变。

源码:

<template><a-drawertitle="物品入库":maskClosable="false"placement="right":closable="false":visible="show":width="1200"@close="onClose"style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;"><a-form :form="form" layout="horizontal"><a-row :gutter="32"><a-col :span="12"><a-form-item label='保管人' v-bind="formItemLayout"><a-input v-decorator="['custodian',{ rules: [{ required: true, message: '请输入保管人!' }] }]"/></a-form-item></a-col><a-col :span="12"><a-form-item label='入库人' v-bind="formItemLayout"><a-input v-decorator="['putUser',{ rules: [{ required: true, message: '请输入入库人!' }] }]"/></a-form-item></a-col><a-col :span="24"><a-form-item label='备注消息' v-bind="formItemLayout"><a-textarea :rows="4" v-decorator="['content',{ initialValue: txtcontent, rules: [{ required: true, message: '请输入名称!' }] }]"/></a-form-item></a-col><a-col :span="24"><a-table :columns="columns" :data-source="dataList"><template slot="nameShow" slot-scope="text, record"><a-input v-model="record.name"></a-input></template><template slot="typeShow" slot-scope="text, record"><a-input v-model="record.type"></a-input></template><template slot="typeIdShow" slot-scope="text, record"><a-select v-model="record.typeId" style="width: 100%"><a-select-option v-for="(item, index) in consumableType" :value="item.id" :key="index">{{ item.name }}</a-select-option></a-select></template><template slot="unitShow" slot-scope="text, record"><a-input v-model="record.unit"></a-input></template><template slot="amountShow" slot-scope="text, record"><a-input-number v-model="record.amount" :min="1" :step="1" :precision="2" @change="handleChange(record)"/></template><template slot="consumptionShow" slot-scope="text, record"><a-input-number v-model="record.consumption" :min="0" :max="record.amount" :step="1" :precision="2" @change="handleChange(record)"/></template><template slot="priceShow" slot-scope="text, record"><a-input-number v-model="record.price" :min="0"/></template></a-table><a-button @click="dataAdd" type="primary" ghost size="large" style="margin-top: 10px;width: 100%">新增物品</a-button></a-col></a-row></a-form><div class="drawer-bootom-button"><a-popconfirm title="确定放弃编辑?" @confirm="onClose" okText="确定" cancelText="取消"><a-button style="margin-right: .8rem">取消</a-button></a-popconfirm><a-button @click="handleSubmit" type="primary" :loading="loading">提交</a-button></div></a-drawer>
</template><script>
import {mapState} from 'vuex'
const formItemLayout = {labelCol: { span: 24 },wrapperCol: { span: 24 }
}
export default {name: 'stockAdd',props: {stockAddVisiable: {default: false}},computed: {...mapState({currentUser: state => state.account.user}),show: {get: function () {return this.stockAddVisiable},set: function () {}},txtcontent () {// const string = JSON.stringify(contentlist)let string = ''this.dataList.forEach(item => {string += item.name + item.amount + item.unit + ' '})return string},columns () {return [{title: '序号',dataIndex: 'key'}, {title: '物品名称',dataIndex: 'name',scopedSlots: {customRender: 'nameShow'}}, {title: '所属类型',dataIndex: 'typeId',width: 200,scopedSlots: {customRender: 'typeIdShow'}}, {title: '型号',dataIndex: 'type',scopedSlots: {customRender: 'typeShow'}}, {title: '采购量',dataIndex: 'amount',scopedSlots: {customRender: 'amountShow'}}, {title: '消耗量',dataIndex: 'consumption',scopedSlots: {customRender: 'consumptionShow'}}, {title: '剩余量',dataIndex: 'balance'}, {title: '单位',dataIndex: 'unit',scopedSlots: {customRender: 'unitShow'}}, {title: '单价',dataIndex: 'price',scopedSlots: {customRender: 'priceShow'}}]}},mounted () {this.getConsumableType()},data () {return {dataList: [],formItemLayout,form: this.$form.createForm(this),loading: false,consumableType: [],keynumber: 1,textareacontent: '备注内容'}},methods: {getConsumableType () {this.$get('/cos/consumable-type/list').then((r) => {this.consumableType = r.data.data})},dataAdd () {this.dataList.push({key: this.keynumber++, name: '', type: '', typeId: '', unit: '', amount: 0, consumption: 0, balance: 0, price: 0})},reset () {this.loading = falsethis.form.resetFields()},onClose () {this.reset()this.$emit('close')},handleChange (record) {record.balance = (record.amount - record.consumption).toFixed(2)},handleSubmit () {let price = 0this.dataList.forEach(item => {price += item.price * item.amount})this.form.validateFields((err, values) => {values.price = pricevalues.goods = JSON.stringify(this.dataList)if (!err) {this.loading = truethis.$post('/cos/stock-info/put', {...values}).then((r) => {this.reset()this.$emit('success')}).catch(() => {this.loading = false})}})}}
}
</script><style scoped></style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2660417.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

自己动手写编译器:算术表达式的语法分析实例和代码实现

在编译原理中&#xff0c;语法解析可能是最抽象和难以理解的部分&#xff0c;初学者很容易在这里卡壳。学习抽象知识的最好方法就是在初期先看大量具体实例&#xff0c;获得足够深厚的感性认识后&#xff0c;我们再对感性认知进行推理和抽象从而获得更高级的理性认知&#xff0…

VMware之FTP的简介以及搭建使用计算机端口的介绍

&#x1f3ac; 艳艳耶✌️&#xff1a;个人主页 &#x1f525; 个人专栏 &#xff1a;《产品经理如何画泳道图&流程图》 ⛺️ 越努力 &#xff0c;越幸运 目录 一、FTP介绍 1、什么是FTP&#xff1a; 2、FTP适用于以下情况和应用场景&#xff1a; 3、winServer2012搭…

最长连续子序列 - 华为OD统一考试

OD统一考试(B卷) 分值: 100分 题解: Java / Python / C++ 题目描述 有N个正整数组成的一个序列。给定整数sum,求长度最长的连续子序列,使他们的和等于sum,返回此子序列的长度, 如果没有满足要求的序列,返回-1。 输入描述 第一行输入是:N个正整数组成的一个序列。…

VBA启动问题:vbe6ext.olb不能被加载

1、拷贝文件&#xff1a; 从&#xff1a; C:\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX86\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB 到&#xff1a; C:\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX86\Microsoft Shared\VBA\VBA7.1\VBE…

虹科方案丨L2进阶L3,数据采集如何助力自动驾驶

来源&#xff1a;康谋自动驾驶 虹科方案丨L2进阶L3&#xff0c;数据采集如何助力自动驾驶 原文链接&#xff1a;https://mp.weixin.qq.com/s/qhWy11x_-b5VmBt86r4OdQ 欢迎关注虹科&#xff0c;为您提供最新资讯&#xff01; 12月14日&#xff0c;宝马集团宣布&#xff0c;搭载…

【2024最新版】我用python代码带你看最绚烂的烟花,浪漫永不过时!

2024年就快要到了&#xff0c;提前用python代码给自己做一个烟花秀庆祝一下。本次介绍的python实例是实现一个简易的烟花秀。 一、步骤分析 总的来说&#xff0c;要实现烟花秀的效果&#xff0c;需要以下几个步骤&#xff1a; 1.1、创建一个类&#xff0c;包含烟花各项粒子的…

解决 Nginx 反向代理中的 DNS 解析问题:从挑战到突破20231228

引言 在使用 Nginx 作为反向代理服务器时&#xff0c;我们可能会遇到各种配置和网络问题。最近&#xff0c;我遇到了一个有趣的挑战&#xff1a;Nginx 在反向代理配置中无法解析特定的域名&#xff0c;导致 502 错误。这个问题的解决过程不仅揭示了 Nginx 的一个不太为人知的功…

力扣刷题记录(20)LeetCode:198、213、337

198. 打家劫舍 我们从第一个开始分析&#xff1a; dp[i]:i表示索引&#xff0c;dp表示当前索引可以拿到的最高金额 索引为0时&#xff0c;可以拿到的最高金额为1&#xff1b; 索引为1时&#xff0c;可以拿到的最高金额就是在索引[0,1]之间取&#xff0c;为2 索引为2时&…

[华为诺亚实验室+中科大提出TinySAM | 比SAM小10倍,精度的超车!]

文章目录 概要整体架构流程Related Work技术细节小结 概要 最近&#xff0c;Segment Anything Model (SAM) 已经展示出了强大的分割能力&#xff0c;在计算机视觉领域引起了广泛关注。基于预训练的 SAM 的大量研究工作已经开发了各种应用&#xff0c;并在下游视觉任务上取得了令…

leaflet学习笔记-自定义Icon(四)

前言 leaflet的marker可以使用icon&#xff0c;所以这篇文章我们自定义一个icon&#xff0c;并在marker中使用&#xff0c;满足我的恶趣味 实例化Icon 首先准备一个你喜欢的图片&#xff0c;并将它添加到你的项目中&#xff0c;这里我找了一张本人的卡通图片 icon实例化代码&…

121. 买卖股票的最佳时机(Java)

给定一个数组 prices &#xff0c;它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票&#xff0c;并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 返回你可以从这笔交易中获取的最大利润。…

二分查找及其复杂的计算

&#xff08;一&#xff09;二分查找及其实现 二分查找&#xff0c;也称为折半查找&#xff0c;是一种高效的搜索算法&#xff0c;用于在有序数组&#xff08;或有序列表&#xff09;中查找特定元素的位置。 二分查找的基本思想是将待查找的区间不断地二分&#xff0c;然后确…

静态HTTP:为什么它如此重要

静态HTTP是互联网上使用最广泛的数据传输协议之一&#xff0c;它在Web应用程序中扮演着至关重要的角色。本文将探讨静态HTTP的重要性及其在Web开发中的应用。 一、静态HTTP的定义和优势 静态HTTP是指服务器上预先生成好的静态文件&#xff0c;这些文件包含HTML、CSS、JavaScr…

erp是什么意思啊?erp系统中有哪些模块?

对于在企业管理领域深耕的人来说&#xff0c;erp这个名字一定不陌生&#xff0c;甚至可以说是他们日常工作中必不可少的重要伙伴。那么&#xff0c;erp究竟是什么意思&#xff1f;erp系统中包含着哪些模块&#xff1f;又是如何协助企业日常运作的呢&#xff1f;今天就让我们一起…

Boot Camp分区备份还原工具boot Camp迁移助手---Winclone pro 10

Winclone Pro 10是一款专为Mac用户设计的先进Windows系统备份和迁移工具。它提供了强大而易于使用的功能&#xff0c;让用户能够轻松地创建、克隆和还原Windows系统&#xff0c;并在Mac上运行。以下是Winclone Pro 10的主要功能和特点&#xff1a; 完整的系统备份和还原&#…

【最新报道】初窥Windows AI 工作室

自我介绍 做一个简单介绍&#xff0c;酒研年近48 &#xff0c;有20多年IT工作经历&#xff0c;目前在一家500强做企业架构&#xff0e;因为工作需要&#xff0c;另外也因为兴趣涉猎比较广&#xff0c;为了自己学习建立了三个博客&#xff0c;分别是【全球IT瞭望】&#xff0c;【…

Vue - Class和Style绑定详解

1. 模板部分 <template><div><!-- Class 绑定示例 --><div :class"{ active: isActive, text-danger: hasError }">Hello, Vue!</div><!-- Class 绑定数组示例 --><div :class"[activeClass, errorClass]">Cla…

大数据Doris(四十三):创建物化视图

文章目录 创建物化视图 一、首先你需要有一个Base表

Android---Kotlin 学习013

互操作性和可空性 Java 世界里所有对象都可能是 null&#xff0c;而 kotlin 里面不能随便给一个变量赋空值的。所有&#xff0c;kotlin 取调用 java 的代码就很容易出现返回一个 null&#xff0c;而 Kotlin 的接收对象不能为空&#xff0c;你不能想当然地认为 java 的返回值就…

(13)Linux 进程的优先级、进程的切换以及环境变量等

前言&#xff1a;我们先讲解进程的优先级。然后讲解进程的切换&#xff0c;最后我们讲解环境变量&#xff0c;并且做一个 "让自己的可执行程序不带路径也能执行"的实践&#xff0c;讲解环境变量的到如何删除&#xff0c;最后再讲几个常见的环境变量。 一、进程优先级…