<template> <div class="box-content"> <a-form :style="{ width: '600px' }" @submit="handleSubmit"> <a-form-item label="任务名称"> <a-input v-model="form.name" placeholder="网站名称" /> </a-form-item> <a-form-item label="采集网址"> <a-input v-model="form.gather" placeholder="例如:https://ecp.sgcc.com.cn" /> </a-form-item> <a-form-item label="网站介绍"> <a-space direction="vertical" size="large" style="width: 100%"> <a-mention v-model="form.introduction" :data="['Bytedance', 'Bytedesign', 'Bytenumner']" type="textarea" placeholder="请输入网站介绍" /> </a-space> </a-form-item> <a-form-item label="模板名称"> <a-button class="custom-button" html-type="submit">选择模板</a-button> </a-form-item> <a-form-item> <a-button class="save-button">保存设置</a-button> </a-form-item> </a-form> </div> </template> <script lang="ts" setup> import { reactive, defineExpose } from 'vue'; interface FormData { name: string; gather: string; introduction: string; } const form = reactive<FormData>({ name: '', gather: '', introduction: '', }); function handleSubmit() { console.log('Form submitted:', form); } defineExpose({ form, handleSubmit, }); </script> <style lang="less" scoped> .custom-button { border: 1px solid rgb(25, 141, 147); color:rgb(25,141,147); } .custom-button:hover{ border: 1px solid rgb(25, 141, 147); color:rgb(25,141,147); } .box-content { width: 100%; background-color: #ffffff; border-radius: 4px; padding: 16px; margin: 16px; } .save-button { width: 120px; background-color: rgb(25, 141, 147); color: #ffffff; } </style>请检查代码并修复
时间: 2024-04-22 17:25:03 浏览: 182
代码中存在一个错误,在 <a-input>
组件的 v-model
属性中,form.name
和 form.gather
的绑定应该使用 .trim
进行修饰,以去除输入的前后空格。修复后的代码如下:
<template>
<div class="box-content">
<a-form :style="{ width: '600px' }" @submit="handleSubmit">
<a-form-item label="任务名称">
<a-input v-model.trim="form.name" placeholder="网站名称" />
</a-form-item>
<a-form-item label="采集网址">
<a-input v-model.trim="form.gather" placeholder="例如:https://ecp.sgcc.com.cn" />
</a-form-item>
<a-form-item label="网站介绍">
<a-space direction="vertical" size="large" style="width: 100%">
<a-mention
v-model="form.introduction"
:data="['Bytedance', 'Bytedesign', 'Bytenumner']"
type="textarea"
placeholder="请输入网站介绍"
/>
</a-space>
</a-form-item>
<a-form-item label="模板名称">
<a-button class="custom-button" html-type="submit">选择模板</a-button>
</a-form-item>
<a-form-item>
<a-button class="save-button">保存设置</a-button>
</a-form-item>
</a-form>
</div>
</template>
<script lang="ts" setup>
import { reactive, defineExpose } from 'vue';
interface FormData {
name: string;
gather: string;
introduction: string;
}
const form = reactive<FormData>({
name: '',
gather: '',
introduction: '',
});
function handleSubmit() {
console.log('Form submitted:', form);
}
defineExpose({
form,
handleSubmit,
});
</script>
<style lang="less" scoped>
.custom-button {
border: 1px solid rgb(25, 141, 147);
color: rgb(25, 141, 147);
}
.custom-button:hover {
border: 1px solid rgb(25, 141, 147);
color: rgb(25, 141, 147);
}
.box-content {
width: 100%;
background-color: #ffffff;
border-radius: 4px;
padding: 16px;
margin: 16px;
}
.save-button {
width: 120px;
background-color: rgb(25, 141, 147);
color: #ffffff;
}
</style>
修复后的代码中,使用 v-model.trim
替代了原先的 v-model
,确保输入的值不包含前后空格。
相关推荐










