1.上一章--餓了麼loading圖、
2.蒼渡大神源碼--項目源碼地址
3.UI框架--Mint UI
4.數據接口--接口API
5.下一章--組件動畫css
1.UI圖以下
html
2.shop.vue頁面代碼修改以下vue
<template> <div id="shop" class="bgfff"> <div class="topbg"> <img class="topbgimg" :src="imgpath+shopinfo.image_path"> </div> <div class="shoptop"> <div class="toptop ih30"> <icon class="backicon" name="back"></icon> <span class="right"> <icon class="backicon2" name="cart"></icon> <icon class="backicon2" name="more"></icon> </span> </div> <div class="topfoot"> <div class="topleft"> <img src=""> </div> <div class="topright nowarp"> <div class="foota"> <div class="footamain fs1-2 nowarp">超出迴音長麼哈哈哈哈哈音長麼</div> <icon name="right" class=" icon3"></icon> </div> <div class="footb nowarp"> <div class="nowarp">公告:這是一條公司擬水電費可死定了房價酸辣粉機</div> </div> <div class="footc"> <span class="footcmain"><span>蜂鳥專送</span>•<span>約31分鐘</span></span> </div> </div> </div> </div> <div class="shopmid mgtop10"> <div class="midtop"><span class="te">特</span><span>16元特價秒殺</span><span class="right">3個活動 <icon name="down" class="icon4"></icon></span></div> <div class="mytab"> <div class="on">商品</div> <div>評價4.8分</div> </div> </div> <div class="shopmain"> <div class="mianleft"> <div class="leftdiv on"> <div > <icon class="icon5" name="hot"></icon> <span>熱銷</span> </div> </div> <div class="leftdiv"> <div> <icon class="icon5" name="discount"></icon> <span>優惠</span> </div> </div> <div class="leftdiv"> <div> <span>很長的蔡明</span> </div> </div> <div class="leftdiv"> <div> <span>段蔡明</span> </div> </div> <div class="leftdiv"> <div> <span>菜名</span> </div> </div> <div class="leftdiv"> <div> <span>菜名</span> </div> </div> <div class="leftdiv"> <div> <span>菜名</span> </div> </div> </div> <div class="mainright"> <div class="item"> <div class="itemtop ih30 after"> <span class="fs15">熱銷</span> <span class="fs0-8 col9f">你們都愛吃纔是真的好吃</span> </div> <div class="itemmain"> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> </div> </div> </div> </div> <div class="foot"> <div class="footleft"> <div class="footlogo"><icon name="footcar" class="footicon"></icon></div> <div class="footmain">未選購商品</div> </div> <div class="footright"> ¥20起送 </div> </div> </div> </template> <script> export default { data () { return { } }, components:{ //註冊組件 }, mounted:function(){ //生命週期 }, computed:{ //計算屬性 }, methods:{ //函數 } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> .shoptop{ height:120px; background-color: rgba(119,103,137,.43); box-sizing:border-box; padding:10px 10px 0px 10px; position: relative; } .topbg{ position: absolute; width:100%; height:120px; left:0px; right:0px; overflow:hidden; } .topbgimg{ width:100%; filter: blur(10px); } .backicon{ height:30px; width:30px; } .backicon2{ height:25px; width:25px; } .toptop{ margin-bottom:10px; } .topfoot{ height:70px; display:flex; } .topleft{ height:80px; width:80px; background-color:#3c3c3c; margin-right:10px; border-radius:3px; box-shadow:0 0 5px #3c3c3c; } .topleft>img{ max-width:100%; max-height:100%; } .topright,.topleft{ float:left; } .topright{ height:100%; flex:1; } .foota{ height:30px; color:white; line-height:30px; display:flex; } .icon3{ width:20px; height:20px; margin-top:5px; } .footc{ height:20px; line-height:20px; font-size:12px; } .footb{ font-size:12px; color:white; } .footcmain{ background-color:#0097FF; color:white; padding:0px 5px; } .shopmid{ padding:10px 10px 0px 10px; margin-bottom:10px; border-bottom:2px solid #F8F8F8; } .midtop{ font-size:12px; } .te{ background-color:#F08449; padding:0px 1px; color:white; } .mytab{ overflow:hidden; margin-top:10px; } .mytab>div{ float:left; padding-bottom:10px; margin-right:10px; border-bottom:2px solid white; } .mytab>div.on{ color:#0B89FF; border-color:#0B89FF; } .leftdiv{ width:60px; padding:0px 10px; color:#727272; background-color:#F8F8F8; } .leftdiv>div{ padding:15px 0px; border-bottom:1px solid #F1F1F1; } .leftdiv.on{ background-color:white; color:#080808; } .leftdiv.on>div{ border:0px; } .icon5{ width:15px; height:15px; } .mianleft{ width:80px; box-sizing:border-box; overflow:scroll; } #shop{ display:-webkit-box; -webkit-box-orient:vertical; height:100vh; } .shopmain{ -webkit-box-flex:1; display:-webkit-box; overflow:hidden; } .mainright{ -webkit-box-flex:1; overflow:scroll; padding-left:10px; } .foot{ height:50px; line-height:50px; background-color:#594C46; display:flex; } .footleft{ flex:2; display:flex; } .footright{ flex:1; text-align:center; color:#B7B7B7; background-color:#61686A; } .footlogo{ text-align:center; width:50px; height:50px; border-radius:50%; background-color:#515151; margin:0px 10px; border:3px solid #444446; transform:translatey(-15px) } .footicon{ width:40px; height:40px; margin-top:7px; } .footmain{ height:50px; color:#ADADAD; font-size:0.8rem; } .itemmain{ padding-right:10px; } .iteminfo{ height:70px; display:flex; padding:10px 0px; } .infoimgbox{ width:70px; height:70px; margin-right:5px; background-color:red; } .infoimgbox>img{ width:100%; height:100%; } .inforight{ flex:1; } .ih20{ height:20px; line-height:20px; } .ih15{ height:15px; line-height:15px; } .addicon{ width:20px; height:20px; } .zk{ background-color:#FF5F15; padding:0px 3px; color:white; border:1px solid #FF5F15; } .yh{ padding:0px 3px; color:#FF5F15; border:1px solid #FF5F15; } </style>
3.頁面以下
node
4.請求數據
先請求一個固定餐館的數據,參數寫死,api以下
4.1在data
中命名變量shopinfo
來存放餐館信息
4.2在mounted
中寫餐館數據的請求git
mounted:function(){ //生命週期 //餐館詳情 this.$http.get('http://cangdu.org:8001/shopping/restaurant/1').then(response => { console.log(response); this.shopinfo=response.body; }, response => { console.log(response); }); },
結果以下
github
ok!數據請求成功!web
4.3渲染餐館數據
渲染後頁面以下
segmentfault
這裏有兩個問題
(1)不能獲取配送時間,這個是API沒有給,可是在商家列表有配送時間,點擊列表進入商家詳情時能夠傳過來,先不 管。
(2)圖片是有域名地址的,API返回圖片地址不徹底,因此咱們先設置一個變量imgpath
來存放圖片域名,再加上API返回的圖片地址就能顯示了,data
修改以下api
data () { return { imgpath:'http://cangdu.org:8001/img/', //商家頭像的路徑地址path shopinfo:"" } },
html修改以下框架
<template> <div id="shop" class="bgfff"> <div class="topbg"> <img class="topbgimg" :src="imgpath+shopinfo.image_path"> </div> <div class="shoptop"> <div class="toptop ih30"> <icon class="backicon" name="back"></icon> <span class="right"> <icon class="backicon2" name="cart"></icon> <icon class="backicon2" name="more"></icon> </span> </div> <div class="topfoot"> <div class="topleft"> <img :src="imgpath+shopinfo.image_path"> </div> <div class="topright nowarp"> <div class="foota"> <div class="footamain fs1-2 nowarp">{{shopinfo.name}}</div> <icon name="right" class=" icon3"></icon> </div> <div class="footb nowarp"> <div class="nowarp">公告:{{shopinfo.promotion_info}}</div> </div> <div class="footc"> <span class="footcmain"><span v-if="shopinfo.delivery_mode">{{shopinfo.delivery_mode.text}}•</span><span>約{{shopinfo.order_lead_time}}</span></span> </div> </div> </div> </div> <div class="shopmid mgtop10"> <div v-if="shopinfo.activities" class="midtop"><span class="te mgr5">{{shopinfo.activities[0].icon_name}}</span><span>{{shopinfo.activities[0].description}}</span><span class="right">{{shopinfo.activities.length}}個活動 <icon name="down" class="icon4"></icon></span></div> <div class="mytab"> <div class="on">商品</div> <div>評價{{shopinfo.rating}}分</div> </div> </div> <div class="shopmain"> <div class="mianleft"> <div class="leftdiv on"> <div > <icon class="icon5" name="hot"></icon> <span>熱銷</span> </div> </div> <div class="leftdiv"> <div> <icon class="icon5" name="discount"></icon> <span>優惠</span> </div> </div> <div class="leftdiv"> <div> <span>很長的蔡明</span> </div> </div> <div class="leftdiv"> <div> <span>段蔡明</span> </div> </div> <div class="leftdiv"> <div> <span>菜名</span> </div> </div> <div class="leftdiv"> <div> <span>菜名</span> </div> </div> <div class="leftdiv"> <div> <span>菜名</span> </div> </div> </div> <div class="mainright"> <div class="item"> <div class="itemtop ih30 after"> <span class="fs15">熱銷</span> <span class="fs0-8 col9f">你們都愛吃纔是真的好吃</span> </div> <div class="itemmain"> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> <div class="iteminfo after"> <div class="infoimgbox"> <img src=""> </div> <div class="inforight"> <div class="fs15 ih20">宮保雞丁</div> <div class="ih15 col9f"><span class="fs10 mgl">月售857份</span><span class="fs10 mgl">好評率97%</span></div> <div class="ih15"><span class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"><span class="colred fs12">¥</span><span class="colred mgr5">25</span><span class="fs12 col9f midline">¥56</span><icon name="add" class="addicon right" ></icon></div> </div> </div> </div> </div> </div> </div> <div class="foot"> <div class="footleft"> <div class="footlogo"><icon name="footcar" class="footicon"></icon></div> <div class="footmain">未選購商品</div> </div> <div class="footright"> ¥20起送 </div> </div> </div> </template>
4.4請求餐館的菜品信息,API以下
在data中設置shopmean
來存放食品信息
data () { return { imgpath:'http://cangdu.org:8001/img/', //商家頭像的路徑地址path shopinfo:"", //商家信息 shopmean:"" //食品信息 } },
在mounted
添加請求
//食品詳情 this.$http.get('http://cangdu.org:8001/shopping/v2/menu?restaurant_id=1').then(response => { console.log(response); this.shopmean=response.body; }, response => { console.log(response); });
結果以下
請求成功!
4.5渲染食品頁面
頁面以下
注意
(1)熱銷榜和優惠API貌似返回icon圖片了,可是我用一直報錯,仍是用我們的svg吧,寫死就好了。
(2)多了一個功能就是有的商品能夠選擇樣式。
(3)灰色的價格與折扣API並無返回,我們直接v-if="false"
隱藏了就行,萬一後面又加了呢
頁面html代碼修改以下
<template> <div id="shop" class="bgfff"> <div class="topbg"> <img class="topbgimg" :src="imgpath+shopinfo.image_path"> </div> <div class="shoptop"> <div class="toptop ih30"> <icon class="backicon" name="back"></icon> <span class="right"> <icon class="backicon2" name="cart"></icon> <icon class="backicon2" name="more"></icon> </span> </div> <div class="topfoot"> <div class="topleft"> <img :src="imgpath+shopinfo.image_path"> </div> <div class="topright nowarp"> <div class="foota"> <div class="footamain fs1-2 nowarp">{{shopinfo.name}}</div> <icon name="right" class=" icon3"></icon> </div> <div class="footb nowarp"> <div class="nowarp">公告:{{shopinfo.promotion_info}}</div> </div> <div class="footc"> <span class="footcmain"><span v-if="shopinfo.delivery_mode">{{shopinfo.delivery_mode.text}}•</span><span>約{{shopinfo.order_lead_time}}</span></span> </div> </div> </div> </div> <div class="shopmid mgtop10"> <div v-if="shopinfo.activities" class="midtop"><span class="te mgr5">{{shopinfo.activities[0].icon_name}}</span><span>{{shopinfo.activities[0].description}}</span><span class="right">{{shopinfo.activities.length}}個活動 <icon name="down" class="icon4"></icon></span></div> <div class="mytab"> <div class="on">商品</div> <div>評價{{shopinfo.rating}}分</div> </div> </div> <div class="shopmain"> <div class="mianleft"> <div v-for="(item,index) in shopmean" class="leftdiv on"> <div > <icon v-if="index==0" class="icon5" name="hot"></icon> <icon v-if="index==1" class="icon5" name="discount"></icon> <span class="fs0-8">{{item.name}}</span> </div> </div> </div> <div class="mainright"> <div class="item" v-for="item in shopmean"> <div class="itemtop ih30 after"> <span class="fs15">{{item.name}}</span> <span class="fs0-8 col9f">{{item.description}}</span> </div> <div class="itemmain"> <div v-for="items in item.foods" class="iteminfo after"> <div class="infoimgbox"> <img :src="imgpath+items.image_path"> </div> <div class="inforight"> <div class="fs15 ih20">{{items.name}}</div> <div class="ih15 col9f"><span class="fs10 mgl">{{items.tips}}</span></div> <div class="ih15"><span v-if="false" class="fs10 mgl"><span class="zk">7折</span><span class="yh">每單限1份優惠</span></span></div> <div class="ih20"> <span class="colred fs12">¥</span> <span class="colred mgr5">{{items.specfoods[0].price}}</span> <span v-if="false" class="fs12 col9f midline">¥56</span> <icon v-if="items.specfoods.length==1" name="add" class="addicon right" ></icon> <span class="fs12 right gz" v-if="items.specfoods.length>1">選規則</span> </div> </div> </div> </div> </div> </div> </div> <div class="foot"> <div class="footleft"> <div class="footlogo"><icon name="footcar" class="footicon"></icon></div> <div class="footmain">未選購商品</div> </div> <div class="footright"> ¥20起送 </div> </div> </div> </template>
我們商家評價頁面尚未寫
1.在data中新建變量shoporscore
來控制顯示商品仍是評價(true顯示商品false顯示評價)
data () { return { imgpath:'http://cangdu.org:8001/img/', //商家頭像的路徑地址path shopinfo:"", //商家信息 shopmean:"", //食品信息 shoporscore:true //商家仍是評價 } },
2.將數據綁定到元素上來控制顯示隱藏
在shopmain
,foot
div上添加判斷v-if="shoporscore"
在foot
div下新建評價div
<div v-if="!shoporscore"> 評價div </div>
3.點擊事件來改變shoporscore
的值,同時綁定classon
來改變元素的樣式
<div class="mytab"> <div @click="shoporscore=true" :class="{ on:shoporscore }">商品</div> <div @click="shoporscore=false" :class="{ on:!shoporscore }" >評價{{shopinfo.rating}}分</div> </div>
4.結果以下
ok!轉換成功,下面就來寫評價的樣式。
4.1UI圖
4.2樣式
評論div的html以下
<div class="score" v-if="!shoporscore"> <div class="scoretop"> <div class="scoretopleft"> <div class="fs1-2 colf60">4.4</div> <div class="fs15 col9f">綜合評價</div> <div class="fs0-8 col9f">高於周邊商家76.9%</div> </div> <div class="scoretopright"> <div><span class="fs15 col9f">評價服務</span></div> <div><span class="fs15 col9f">菜品評價</span></div> <div><span class="fs15 col9f">送達時間</span></div> </div> </div> <div class="scoremain"> <div class="scoremaintop after"> <div class="ih30 fs0-8 sty1 on">所有(759)</div> <div class="ih30 fs0-8 sty1">很好啊的(759)</div><div class="ih30 fs0-8 sty1">很好啊的(759)</div> <div class="ih30 fs0-8 sty1">很好啊的(759)</div><div class="ih30 fs0-8 sty1">很好啊的(759)</div> <div class="ih30 fs0-8 sty2">差評(759)</div> </div> <div class="scoremaininfo"> <div class="scoreitem after"> <div class="scoreitemleft"> <img > </div> <div class="scoreitemright fs12 col9f"> <div> <span>姓名</span> <span class="right">2017-02-06</span> </div> <div> 星星 </div> <div> 很好吃的評論 </div> <div class="scoreimgbox"> <img><img> </div> <div class="namebox"> <div>炒雞好吃煲</div> <div>無敵辣雞翅</div> </div> </div> </div> <div class="scoreitem"> <div class="scoreitemleft"> <img > </div> <div class="scoreitemright fs12 col9f"> <div> <span>姓名</span> <span class="right">2017-02-06</span> </div> <div> 星星 </div> <div> 很好吃的評論 </div> <div> <img><img> </div> <div class="namebox"> <div>炒雞好吃煲</div> <div>無敵辣雞翅</div> </div> </div> </div> </div> </div> </div>
css以下
.scoretop{ display:flex; padding:0px 10px 10px 10px; border-bottom:10px solid #F5F5F5; } .scoretopleft{ flex:1; text-align:center; } .scoretopright{ flex:1; } .scoremain{ padding:0px 10px; } .scoremaintop{ padding:10px 0px 5px 0px; display:flex; flex-wrap:wrap; } .scoremaintop>div{ padding:0px 8px; border-radius:5px; margin-right:5px; margin-bottom:5px; } .sty1{ background-color:#EBF5FF; color:#9f9f9f; } .sty1.on{ background-color:#3190E8; color:#fff; } .sty2{ background-color:#F5F5F5; color:#AFAFAF; } .scoreitem{ display:flex; margin-top:10px; } .scoreitemleft{ width:50px; height:50px; margin-right:10px; background-color:red; } .scoreitemleft>img{ width:100%; border-radius:50%; } .scoreitemright{ flex:1; } .namebox{ display:flex; flex-wrap: wrap; } .namebox>div{ border:1px solid; padding:3px 3px; margin-right:5px; border-radius:3px; margin-bottom:5px; } .score{ padding-top:10px; flex:1; overflow: scroll; } .scoreimgbox>img{ width:4rem; height:4rem; background-color:red; margin-right:10px; }
頁面以下
(星星沒有寫是由於在miste.vue裏我們已經寫過了)
5.請求評價數據
在data
中建立變量score
,scorerating
,scoretags
,來存放評價數據
data () { return { imgpath:'http://cangdu.org:8001/img/', //商家頭像的路徑地址path shopinfo:"", //商家信息 shopmean:"", //食品信息 shoporscore:true, //商家仍是評價 score:"", //評價信息 scorerating:"", //評價分數 scoretags:"", //評價分類 scoreindex:0 //選中第幾個評價分類 } },
接口API如圖(參數先傳個死值)
在mounted
中寫請求
//評論詳情 this.$http.get('http://cangdu.org:8001/ugc/v2/restaurants/1/ratings?offset=0&limit=10').then(response => { console.log(response); this.score=response.body; }, response => { console.log(response); }); //評論分數 this.$http.get('http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/scores').then(response => { console.log(response); this.scorerating=response.body; }, response => { console.log(response); }); //評論分類 this.$http.get('http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/tags').then(response => { console.log(response); this.scoretags=response.body; }, response => { console.log(response); });
結果如圖
ok!請求成功
1.寫評價星星的組件
在src文件夾下的的 components下新建stars/stars.vue,頁面代碼以下(在miste.vue一章中我們寫過)
<template> <div> <div class="xxbox fs10 mgl"> <span v-for="(itemxx,index) in 5" class="xxspan1"><icon v-if="index+1<=num" name="xx" class="xx"></icon><icon v-if="index+1>num" name="xx2" class="xx"></icon><span v-if="num-(index)>0&&num-(index)<1" :class="xxclass+(num*10-index*10)"><icon name="xx" class="xx"></icon></span></span> </div> </div> </template> <script> export default { data () { return { xxclass:"xxspan2 w", //星星的class } }, props:[ "num" ] } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> .xxdiv{ height:25px; line-height:25px; } .xxbox{ display:inline-block; height:25px; box-sizing:border-box; } .xxbox>span{ margin-right:-2px; } .xxspan1{ position:relative; display:inline-block; margin-right:1px !important; } .xxspan2{ display:inline-block; position:absolute; left:0px; overflow: hidden; } .w1{ width:10%; } .w2{ width:20%; } .w3{ width:30%; } .w4{ width:40%; } .w5{ width:50%; } .w6{ width:60%; } .w7{ width:70%; } .w8{ width:80%; } .w9{ width:90%; } .xx{ width:10px; height:10px; } </style>
這裏注意,props是父組件傳遞給子組件的值,在子組件直接調用便可。這裏的num表明評分的等級如4.8,3.2等
在shop.vue中引入並註冊
import stars from '../../components/stars/stars'
在components
中註冊組件
components:{ //註冊組件 stars },
在代碼中直接調用
<stars num="你要傳遞給子組件的值"></stars>
2.評價div代碼修改以下
<div class="score" v-if="!shoporscore"> <div class="scoretop"> <div class="scoretopleft"> <div class="fs1-2 colf60">{{shopinfo.rating}}</div> <div class="fs15 col9f">綜合評價</div> <div class="fs0-8 col9f">高於周邊商家{{parseInt(scorerating.compare_rating*100)}}%</div> </div> <div class="scoretopright"> <div><span class="fs15 col9f mgr5">評價服務</span><stars :num="scorerating.service_score.toFixed(1)"></stars><span class="colf60 right">{{scorerating.service_score.toFixed(1)}}</span></div> <div><span class="fs15 col9f mgr5">菜品評價</span><stars :num="scorerating.food_score.toFixed(1)"></stars><span class="colf60 right">{{scorerating.food_score.toFixed(1)}}</span></div> <div><span class="fs15 col9f mgr5">送達時間</span><span class="fs15 colf60">{{scorerating.deliver_time}}分鐘</span></div> </div> </div> <div class="scoremain"> <div class="scoremaintop after"> <div v-for="(item,index) in scoretags" class="ih30 fs0-8" :class="{sty2:item.unsatisfied,sty1:!(item.unsatisfied),on:index==scoreindex}">{{item.name}}({{item.count}})</div> </div> <div class="scoremaininfo"> <div v-for="item in score" class="scoreitem after"> <div class="scoreitemleft"> <img :src="imgaddpath(item.avatar)" > </div> <div class="scoreitemright fs12 col9f"> <div> <span>{{item.username}}</span> <span class="right">{{item.rated_at}}</span> </div> <div> <stars :num="item.rating_star"></stars> </div> <div> {{item.time_spent_desc}} </div> <div class="scoreimgbox"> <img v-for="itema in item.item_ratings" :src="imgaddpath(itema.image_hash)"> </div> <div class="namebox"> <div v-for="itemb in item.item_ratings">{{itemb.food_name}}</div> </div> </div> </div> </div> </div> </div>
頁面如圖
不顯示圖片我看了看是API沒有返回數據
shop.vue最終修改以下
<template> <div id="shop" class="bgfff"> <div class="topbg"> <img class="topbgimg" :src="imgpath+shopinfo.image_path"> </div> <div class="shoptop"> <div class="toptop ih30"> <icon class="backicon" name="back"></icon> <span class="right"> <icon class="backicon2" name="cart"></icon> <icon class="backicon2" name="more"></icon> </span> </div> <div class="topfoot"> <div class="topleft"> <img :src="imgpath+shopinfo.image_path"> </div> <div class="topright nowarp"> <div class="foota"> <div class="footamain fs1-2 nowarp">{{shopinfo.name}}</div> <icon name="right" class=" icon3"></icon> </div> <div class="footb nowarp"> <div class="nowarp">公告:{{shopinfo.promotion_info}}</div> </div> <div class="footc"> <span class="footcmain"><span v-if="shopinfo.delivery_mode">{{shopinfo.delivery_mode.text}}•</span><span>約{{shopinfo.order_lead_time}}</span></span> </div> </div> </div> </div> <div class="shopmid mgtop10"> <div v-if="shopinfo.activities" class="midtop"><span class="te mgr5">{{shopinfo.activities[0].icon_name}}</span><span>{{shopinfo.activities[0].description}}</span><span class="right">{{shopinfo.activities.length}}個活動 <icon name="down" class="icon4"></icon></span></div> <div class="mytab"> <div @click="shoporscore=true" :class="{ on:shoporscore }">商品</div> <div @click="shoporscore=false" :class="{ on:!shoporscore }" >評價{{shopinfo.rating}}分</div> </div> </div> <div v-if="shoporscore" class="shopmain"> <div class="mianleft"> <div v-for="(item,index) in shopmean" class="leftdiv"> <div > <icon v-if="index==0" class="icon5" name="hot"></icon> <icon v-if="index==1" class="icon5" name="discount"></icon> <span class="fs0-8">{{item.name}}</span> </div> </div> </div> <div class="mainright"> <div class="item" v-for="item in shopmean"> <div class="itemtop padtop10 ih30 after"> <span class="fs15">{{item.name}}</span> <span class="fs0-8 col9f">{{item.description}}</span> </div> <div class="itemmain"> <div v-for="items in item.foods" class="iteminfo after"> <div class="infoimgbox"> <img :src="imgpath+items.image_path"> </div> <div class="inforight"> <div class="fs15 ih20">{{items.name}}</div> <div class="ih15 col9f"><span class="fs10 mgl">{{items.tips}}</span></div> <div class="ih15"><span v-if="false" class="fs10 mgl"><span class="zk">包裝費</span><span class="yh">{{}}</span></span></div> <div class="ih20"> <span class="colred fs12">¥</span> <span class="colred mgr5">{{items.specfoods[0].price}}</span> <span v-if="items.specfoods[0].original_price" class="fs12 col9f midline">¥56</span> <icon v-if="items.specfoods.length==1" name="add" class="addicon right" ></icon> <span class="fs12 right gz" v-if="items.specfoods.length>1">選規則</span> </div> </div> </div> </div> </div> </div> </div> <div v-if="shoporscore" class="foot"> <div class="footleft"> <div class="footlogo"><icon name="footcar" class="footicon"></icon></div> <div class="footmain">未選購商品</div> </div> <div class="footright"> ¥20起送 </div> </div> <div class="score" v-if="!shoporscore"> <div class="scoretop"> <div class="scoretopleft"> <div class="fs1-2 colf60">{{shopinfo.rating}}</div> <div class="fs15 col9f">綜合評價</div> <div class="fs0-8 col9f">高於周邊商家{{parseInt(scorerating.compare_rating*100)}}%</div> </div> <div class="scoretopright"> <div><span class="fs15 col9f mgr5">評價服務</span><stars :num="scorerating.service_score.toFixed(1)"></stars><span class="colf60 right">{{scorerating.service_score.toFixed(1)}}</span></div> <div><span class="fs15 col9f mgr5">菜品評價</span><stars :num="scorerating.food_score.toFixed(1)"></stars><span class="colf60 right">{{scorerating.food_score.toFixed(1)}}</span></div> <div><span class="fs15 col9f mgr5">送達時間</span><span class="fs15 colf60">{{scorerating.deliver_time}}分鐘</span></div> </div> </div> <div class="scoremain"> <div class="scoremaintop after"> <div v-for="(item,index) in scoretags" class="ih30 fs0-8" :class="{sty2:item.unsatisfied,sty1:!(item.unsatisfied),on:index==scoreindex}">{{item.name}}({{item.count}})</div> </div> <div class="scoremaininfo"> <div v-for="item in score" class="scoreitem after"> <div class="scoreitemleft"> <img :src="imgaddpath(item.avatar)" > </div> <div class="scoreitemright fs12 col9f"> <div> <span>{{item.username}}</span> <span class="right">{{item.rated_at}}</span> </div> <div> <stars :num="item.rating_star"></stars> </div> <div> {{item.time_spent_desc}} </div> <div class="scoreimgbox"> <img v-for="itema in item.item_ratings" :src="imgaddpath(itema.image_hash)"> </div> <div class="namebox"> <div v-for="itemb in item.item_ratings">{{itemb.food_name}}</div> </div> </div> </div> </div> </div> </div> </div> </template> <script> import stars from '../../components/stars/stars' export default { data () { return { imgpath:'http://cangdu.org:8001/img/', //商家頭像的路徑地址path shopinfo:"", //商家信息 shopmean:"", //食品信息 shoporscore:true, //商家仍是評價 score:"", //評價信息 scorerating:"", //評價分數 scoretags:"", //評價分類 scoreindex:0 //選中第幾個評價分類 } }, components:{ //註冊組件 stars }, mounted:function(){ //生命週期 //餐館詳情 this.$http.get('http://cangdu.org:8001/shopping/restaurant/1').then(response => { console.log(response); this.shopinfo=response.body; }, response => { console.log(response); }); //食品詳情 this.$http.get('http://cangdu.org:8001/shopping/v2/menu?restaurant_id=1').then(response => { console.log(response); this.shopmean=response.body; }, response => { console.log(response); }); //評論詳情 this.$http.get('http://cangdu.org:8001/ugc/v2/restaurants/1/ratings?offset=0&limit=10').then(response => { console.log(response); this.score=response.body; }, response => { console.log(response); }); //評論分數 this.$http.get('http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/scores').then(response => { console.log(response); this.scorerating=response.body; }, response => { console.log(response); }); //評論分類 this.$http.get('http://cangdu.org:8001/ugc/v2/restaurants/1/ratings/tags').then(response => { console.log(response); this.scoretags=response.body; }, response => { console.log(response); }); }, computed:{ //計算屬性 }, methods:{ //函數 imgaddpath:function(e){ return "https://fuss10.elemecdn.com/"+e+".jpeg" } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> .shoptop{ height:120px; background-color: rgba(119,103,137,.43); box-sizing:border-box; padding:10px 10px 0px 10px; position: relative; } .topbg{ position: absolute; width:100%; height:120px; left:0px; right:0px; overflow:hidden; } .topbgimg{ width:100%; filter: blur(10px); } .backicon{ height:30px; width:30px; } .backicon2{ height:25px; width:25px; } .toptop{ margin-bottom:10px; } .topfoot{ height:70px; display:flex; } .topleft{ height:80px; width:80px; background-color:#3c3c3c; margin-right:10px; border-radius:3px; box-shadow:0 0 5px #3c3c3c; } .topleft>img{ max-width:100%; max-height:100%; border-radius:3px; } .topright,.topleft{ float:left; } .topright{ height:100%; flex:1; } .foota{ height:30px; color:white; line-height:30px; display:flex; } .icon3{ width:20px; height:20px; margin-top:5px; } .footc{ height:20px; line-height:20px; font-size:12px; } .footb{ font-size:12px; color:white; } .footcmain{ background-color:#0097FF; color:white; padding:0px 5px; } .shopmid{ padding:10px 10px 0px 10px; border-bottom:2px solid #F8F8F8; } .midtop{ font-size:12px; } .te{ background-color:#F08449; padding:0px 1px; color:white; } .mytab{ overflow:hidden; margin-top:10px; } .mytab>div{ float:left; padding-bottom:10px; margin-right:10px; border-bottom:2px solid white; } .mytab>div.on{ color:#0B89FF; border-color:#0B89FF; } .leftdiv{ width:60px; padding:0px 10px; color:#727272; background-color:#F8F8F8; } .leftdiv>div{ padding:15px 0px; border-bottom:1px solid #F1F1F1; } .leftdiv.on{ background-color:white; color:#080808; } .leftdiv.on>div{ border:0px; } .icon5{ width:15px; height:15px; } .mianleft{ width:80px; box-sizing:border-box; overflow:scroll; } #shop{ display:-webkit-box; -webkit-box-orient:vertical; height:100vh; } .shopmain{ -webkit-box-flex:1; display:-webkit-box; overflow:hidden; } .mainright{ -webkit-box-flex:1; overflow:scroll; padding-left:10px; } .foot{ height:50px; line-height:50px; background-color:#594C46; display:flex; } .footleft{ flex:2; display:flex; } .footright{ flex:1; text-align:center; color:#B7B7B7; background-color:#61686A; } .footlogo{ text-align:center; width:50px; height:50px; border-radius:50%; background-color:#515151; margin:0px 10px; border:3px solid #444446; transform:translatey(-15px) } .footicon{ width:40px; height:40px; margin-top:7px; } .footmain{ height:50px; color:#ADADAD; font-size:0.8rem; } .itemmain{ padding-right:10px; } .iteminfo{ height:70px; display:flex; padding:10px 0px; } .infoimgbox{ width:70px; height:70px; margin-right:5px; background-color:red; } .infoimgbox>img{ width:100%; height:100%; } .inforight{ flex:1; } .ih20{ height:20px; line-height:20px; } .ih15{ height:15px; line-height:15px; } .addicon{ width:20px; height:20px; } .zk{ background-color:#FF5F15; padding:0px 3px; color:white; border:1px solid #FF5F15; } .yh{ padding:0px 3px; color:#FF5F15; border:1px solid #FF5F15; } .gz{ display:inline-block; background-color:#3190E8; color:white; padding:0px 2px; border-radius:2px; } .scoretop{ display:flex; padding:0px 10px 10px 10px; border-bottom:10px solid #F5F5F5; } .scoretopleft{ flex:2; text-align:center; } .scoretopright{ flex:3; } .scoretopright>div{ display:flex; } .scoremain{ padding:0px 10px; } .scoremaintop{ padding:10px 0px 5px 0px; display:flex; flex-wrap:wrap; } .scoremaintop>div{ padding:0px 8px; border-radius:5px; margin-right:5px; margin-bottom:5px; } .sty1{ background-color:#EBF5FF; color:#9f9f9f; } .sty1.on{ background-color:#3190E8; color:#fff; } .sty2{ background-color:#F5F5F5; color:#AFAFAF; } .scoreitem{ display:flex; margin-top:10px; } .scoreitemleft{ width:50px; height:50px; margin-right:10px; } .scoreitemleft>img{ width:100%; border-radius:50%; } .scoreitemright{ flex:1; } .namebox{ display:flex; flex-wrap: wrap; } .namebox>div{ border:1px solid; padding:3px 3px; margin-right:5px; border-radius:3px; margin-bottom:5px; } .score{ padding-top:10px; flex:1; overflow: scroll; } .scoreimgbox>img{ width:4rem; height:4rem; margin-right:10px; } </style>