我正在实现一个功能,其中用户单击编辑按钮(显示在一行中),该行中的所有详细信息都应传递到表单组件,在该组件中,我应该从参数中获取这些字段的默认值。我不确定如何实现此目标...有人可以建议解决方案吗?
----------inside table component------------------
edit_row(id){
// alert("deleting row " + id);
var d_fname = this.users[id].fname;
var d_lname = this.users[id].lname;
var d_tech = this.users[id].tech;
this.$router.push({name: 'form/', params: {d_fname, d_lname, d_tech}});
// this.$router.push({name:'/form1', params:{d_fname, d_lname, d_tech}});
}
----------------inside form component------------------------
<template>
<form id="form">
<h4>Personal Information</h4>
<br />
<input type="text" placeholder="First Name" v-model="fname" />
<p>{{user_info}}</p>
<br />
<input type="text" placeholder="Last Name" v-model="lname" />
<br />
<input type="text" placeholder="Technologies" v-model="tech" />
<br />
<button type="button" value="submit" @click="submit_info()">Submit</button>
</form>
</template>
<script>
export default {
name: "form1",
props:["d_fname", "d_lname", "d_tech"],
data() {
return {
fname: "",
lname: "",
tech: ""
};
}
}
答案 0 :(得分:2)
您需要在params对象中传递参数作为键值,还需要在路线声明中将props设置为true。
{path: "form/", name:"form", component: FormComponent, props: true}
您应该参考这个。