Laravel 如何清除这些值?
我使用的是一个laravel vue样板。包中有Laravel 如何清除这些值?,laravel,typescript,interface,Laravel,Typescript,Interface,我使用的是一个laravel vue样板。包中有用户CRUD。我做了同样的事情,复制/粘贴,更改了一些细节,使项CRUD。工作正常。问题发生在操作(编辑)之后。我要添加一个新项目,表单中已填充编辑的项目值。表单位于组件的模式中。 不知道我贴在这里的代码的哪一部分,期待 模态: addItem(): void {//this is the actions to call the modal this.isModalAdd = true; this.setModalVisible
用户CRUD
。我做了同样的事情,复制/粘贴,更改了一些细节,使项CRUD
。工作正常。问题发生在操作(编辑
)之后。我要添加一个新项目,表单中已填充编辑的项目值。表单位于组件的模式中。
不知道我贴在这里的代码的哪一部分,期待
模态:
addItem(): void {//this is the actions to call the modal
this.isModalAdd = true;
this.setModalVisible(true);
this.form=this.new_form;
}
edit(item:Item):void{
this.isModalAdd = false;
this.setModalVisible(true);
this.form = { ...item };
}
<ItemsModal v-bind:form='form' v-bind:is-add='isModalAdd' v-bind:is-visible='isModalVisible' ></ItemsModal>//added in the Items template
<script lang="ts">//Items Modal
import { Component, Emit, Prop, Vue } from 'vue-property-decorator';
import { Action, State, namespace } from 'vuex-class';
import checkPassword from '@/utils/checkPassword';
const iStore = namespace('items');
@Component
export default class ItemsModal extends Vue {
@Prop() form;
@Prop() isAdd;
@Prop() isVisible;
@iStore.Action addItem;
@iStore.Action editItem;
@iStore.Action setModalVisible;
@iStore.State isModalLoading;
handleOk() {
if (this.isAdd) {
this.addItem(this.form);
} else {
this.editItem(this.form);
}
}
handleClose() {
this.setModalVisible(false);
}
}
</script>
<template lang="pug">
b-modal(
hide-header-close=true,
:visible='isVisible',
:cancel-title='$t("buttons.cancel")',
:ok-disabled='isModalLoading',
:ok-title='isModalLoading ? $t("buttons.sending") : isAdd ? $t("buttons.add") : $t("buttons.update")',
:title='isAdd ? $t("users.add_user") : $t("users.edit_user")',
@hide='handleClose',
@ok.prevent='handleOk',
)
b-form
b-form-group(
:label='$t("strings.name")'
label-for='name',
)
b-form-input#name(
type='text',
v-model='form.name',
maxlength='191',
required,
)
</template>
addItem():void{//这是调用模态
this.isModalAdd=true;
此.setModalVisible(true);
this.form=this.new_form;
}
编辑(项目:项目):作废{
this.isModalAdd=false;
此.setModalVisible(true);
this.form={…item};
}
//添加到项目模板中
//项目模态
从“Vue属性装饰器”导入{Component,Emit,Prop,Vue};
从“vuex类”导入{Action,State,namespace};
从“@/utils/checkPassword”导入checkPassword;
const-iStore=名称空间('items');
@组成部分
导出默认类ItemsModel扩展Vue{
@Prop()形式;
@Prop()isAdd;
@Prop()是可见的;
@历史事件。行动补充;
@行动编辑项;
@动作设定可视;
@历史状态为模态加载;
handleOk(){
如果(本文件为isAdd){
本.附件(本.表格);
}否则{
此.editItem(此.form);
}
}
handleClose(){
此.setModalVisible(false);
}
}
b-模态(
隐藏标题关闭=真,
:visible='isVisible',
:cancel title='$t(“buttons.cancel”)',
:ok disabled='isModalLoading',
:ok title='isModalLoading?$t(“buttons.sending”):isAdd?$t(“buttons.add”):$t(“buttons.update”),
:title='isAdd?$t(“用户.添加用户”):$t(“用户.编辑用户”),
@隐藏“='handleClose',
@好的,我来帮你,
)
b型
b型群(
:label='$t(“strings.name”)'
='name'的标签,
)
b-表单输入#名称(
type='text',
v-model='form.name',
maxlength='191',
必修的,
)
我觉得你的代码不完整。根据我的猜测,提交表单后,您应该清空表单数据。意味着,在这些方法的添加项(this.form)、this.editItem(this.form)、setModalVisible(false)末尾,您应该清空this.form数据或清空表单的属性。像
this.form = {}
or
this.form.name = null
完成api中的操作后,尝试清空或清空与该表单相关的数据
editItem (form) {
// work with your backend
this.form = {}
}
你能显示模态组件和动作方法的代码吗?@MuhaimenulIslam添加了代码。