props的使用以及axios在前端的傳送和接收
props
在標(biāo)簽添加事件涯捻,根據(jù)這個(gè)事件進(jìn)行跳轉(zhuǎn)浅妆,
<template slot-scope="scope">
<el-button type="primary" size="small" @click="handletoupdate(scope)">編輯</el-button>
</template>
跳轉(zhuǎn)時(shí) 在URL地址上面添加拼接上 id ,這是點(diǎn)擊修改的數(shù)據(jù)汰瘫,就有了唯一的標(biāo)簽
methods :{
handletoupdate(scope){
var _id = scope.row._id;
this.$router.push('/admin/postupdate/' + _id)
},
/admin/postupdate/它的router路由配置
//這里的參數(shù) props:true 可以直接取URL后面的id參數(shù)
{ path : 'postupdate/:id' , component : ()=> import('@/views/Admin_postupdate.vue') , props : true} ,
Admin_postupdate.vue的頁面
//這里的id就是URL后面的id參數(shù)
export default {
props : ['id']
}
post方式
//第一個(gè)參數(shù)就是連接后端的URL狂打,第二個(gè)就是傳送的數(shù)據(jù),第三個(gè)參數(shù)就是在URL上混弥?后面拼接的URL
this.$axios.post('url',param,
{ params :{ _id : this.id } }).then((res)={
//在這里就可以處理一下接受的數(shù)據(jù)
this.form = res.data.info;
//form是data(){ return {}}定義好的數(shù)據(jù)
})
// 在后臺(tái)的接收形式 var _id = req.query._id;
// 接收別的數(shù)據(jù)就是param里面的數(shù)據(jù) var body = req.body
get方式
this.$axios.get('url' ,{ params :{ _id : this.id }}).then((res)=>{
//在這里就可以處理一下接受的數(shù)據(jù)
//想要添加別的數(shù)據(jù)也是在params里面添加
this.form = res.data.info;
//form是data(){ return {}}定義好的數(shù)據(jù)
})
// 在后臺(tái)的接收形式也是 var _id = req.query._id;