1、給父頁面跳轉的地方設置事件
//原來的頁面上展示的信息 <div v-if="!addShow" class="function"> <el-row> <template slot-scope="scope"> <el-button type="success" size="mini" @click="handleEdit(scope.$index, scope.row)">編輯</el-button> //帶參數進行編輯 <el-button type="danger" size="mini" @click="handleDelete(scope.row)">刪除</el-button> </template> </el-row> </div> //要跳轉過去的頁面用隱藏來代替 <div v-if="addShow" class="add-category "> <el-col :span="20" :offset="2"> <el-form :model="formData" :rules="rules" ref="formData" label-position="left"> <el-row> <el-col :span="10"> <el-form-item label="銷售區域名稱" prop="name"> <el-input v-model="formData.name"></el-input> //v-model綁定formData.name(name為需要的字段,formDataw為表格ref綁定的數據) </el-form-item> </el-col> </el-row> <el-col :span="18"> <el-form-item label="銷售區域描述"> <el-input type="textarea" :rows="5" v-model="formData.description"></el-input> </el-form-item> </el-col> <el-col :span="2" :offset="9"> <el-button type="success" @click="handleSubmit('formData')" >確定</el-button> </el-col> <el-col :span="2" :offset="1"> <el-button @click="onCancel">取消</el-button> </el-col> </el-form> </el-col> </div>
2、JS部分
data() { addShow: false //設置要顯示的頁面部分默認為false,隱藏 checkdDistributor: null, }, methods: { // 編輯按鈕 handleEdit(index,row){ this.checkdDistributor = row; //接受傳參 this.addShow = true; // addshow為要顯示的頁面 } } watch: { // 帶參數編輯 checkdDistributor(){ for(let attr in this.formData){ this.formData[attr] = ('' + this.checkdDistributor[attr]); //寫入參數 } } },
3、最后上效果圖
補充:
vue router-link跳轉傳值示例
1、router-link
<router-link :to="{name:'deitail',params:{freezeMon:'2017-10',owerName:'西安'}}" tag="div" ></router-link>
2、routes路由
export default new Router({ routes: [ { path: '/', name: 'Index', component: Index }, { path: '/deitail', name: 'deitail', component: deitail } ]})
3、取值
<h1>{{$route.params.freezeMon}}</h1>
4、小結:router-link跳轉傳值要注意的地方
* to前面要加:
* to后面{中的name值要與路由中的name值一致
* 下面的這種方式是錯誤的
<router-link to="{path:'/deitail',params:{freezeMon:'2017-10',owerName:'西安'}}" tag="div" ></router-link>
新聞熱點
疑難解答