1.思路:
1.1:先获取数据进行页面渲染
先写一个menuInfo
接收菜谱的详细信息
export default {
components: {
DetailHeader, DetailContent, Comment},
data(){
return {
menuInfo:{
}
}
},
1.2:拿到menuId后有两种情况if判断一下有就是正常的发送请求,如果不存在发送重进进入
watch:{
$route:{
handler(){
let {
menuId} = this.$route.query;
if(menuId){
//3.1
menuInfo({
menuId}).then(({
data}) =>{
console.log(data)
this.menuInfo = data.info;
})
}else{
this.$message({
message:"重进进入",
type:"warrning"
})
}
},
immediate:true
}
}
}
效果展示:
1.3:详细代码
<template>
<div class="menu-detail">
<detail-header :info="menuInfo"></detail-header>
<detail-content :info="menuInfo"></detail-content>
<Comment :info="menuInfo"></Comment>
</div>
</template>
<script>
import DetailHeader from './detail-header'
import DetailContent from './detail-content'
import Comment from './comment'
import {
menuInfo} from '@/service/api';
export default {
components: {
DetailHeader, DetailContent, Comment},
data(){
return {
menuInfo:{
userInfo:{
},
raw_material:{
main_material:[],
accessories_material:[]
},
steps:[]
} //1.接收菜谱的详细信息
}
},
watch:{
$route:{
handler(){
//2.menuId从query里面去拿
let {
menuId} = this.$route.query;
//3.拿到menuId后有两种情况if判断一下//有就是正常的
if(menuId){
//3.1发送请求
menuInfo({
menuId}).then(({
data})</