vue3.2路由傳參【使用state方式】

在跳轉(zhuǎn)前的頁面使用 state 參數(shù)

<template>

<div class="modify-button">

<el-table :data="dish_data" style="width: 100%">

? ? <el-table-column align="center" label="操作" min-width="100">

? ? ? ? ? ? <template #default="scope">

? ? ? ? ? ? ? ? ? ? <el-button size="small" type="primary" @click="Edit(scope.row)">編輯</el-button>

? ? ? ? ? ? </template>

? ? </el-table-column>

</el-table>

</div>

</template>

<script setup lang="ts">

import { reactive, toRefs, onMounted, getCurrentInstance, ref } from 'vue'

import { ElMessageBox } from 'element-plus'

import { useRouter } from 'vue-router'

import {getObtaindishes} from '@/api/index'

const { proxy } = getCurrentInstance() as any

const router = useRouter()

const oper_data = reactive({

? ? page: 0,

? ? dish_data: [],

? ? total: 0

})

const {page,dish_data,total} = toRefs(oper_data)

// 請(qǐng)求菜品數(shù)據(jù)

onMounted(() => {

? ? get_dishes()

})

async function get_dishes() {

? ? try {

? ? ? ? let query = {

? ? ? ? ? ? page: oper_data.page

? ? ? ? }

? ? ? ? const res = await getObtaindishes({params:query});

? ? ? ? oper_data.dish_data = res.data.result

? ? ? ? oper_data.total = res.data.total

? ? } catch (e) {

? ? ? ? console.log('error',e);

? ? ? ? new proxy.$tips('服務(wù)器發(fā)生錯(cuò)誤', 'error').mess_age()

? ? }

}

// 編輯商品

const Edit = (scope) => {

? ? const params = JSON.stringify(scope)

? ? router.push({name:'upload',state:{params}}) //注意:此處一定要用params

}

</script>

<style scoped="scoped"></style>

跳轉(zhuǎn)的后頁面接收

console.log('history.state', typeof history.state.params)

const etid_data = history.state.params

if (etid_data != undefined) {

? ? const value = JSON.parse(etid_data)

? ? const { category, name, unitprice, unit, image, _id } = value

? ? oper_data.id = _id,

? ? oper_data.catevalue = category,

? ? oper_data.name = name,

? ? oper_data.unitprice = unitprice,

? ? oper_data.compvalue = unit,

? ? oper_data.goodsimage = image

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容