首先在你要动态获取添加信息的路由表path后面设置一个:id(冒号后面这个是可变的),:id表示*,任意的,例:
{path:'/edit/:id',
component:Edit}
也就是说/edit/1 ,/edit/2 ,/edit/a ,/edit/456 都会匹配到这个路由规则
可以在匹配到的路由组件中通过 this.$route.parmas.id 来获取路由参数
还需要你在你需要跳转的地方拼接一下这个ID
在router-link :to="'/edit/'+item.id"就会跳转到相应的内容页面
然后在:使用data收集表单数据,然后在使用created(){}生命周期-创建,调用methods中的函数,这个函数要给data中的表单提供数据
export default {
data () {
return {
formData:{
name:'',
bio:''
}
}
},
created(){
this.handleSubmit ()
},
methods: {
handleSubmit () {
const id=this.$route.params.id
axios({
method: 'GET',
url:`http//:localhost:3000/${id}`
}).then(res=>{
this.formData=res.data
})
}
}
}