基于vue.js仿淘寶收貨地址并設(shè)置默認地址的案例分析
這個案例主要是渲染地址列表,然后設(shè)置默認地址,與淘寶的收貨地址功能一樣,具體自行查看自己的淘寶收貨地址;
效果圖:
html結(jié)構(gòu)
<!--the-address--> <div class="the-address"> <div class="adr-tent" id="vue-address"> <table class="adr-table"> <thead class="table-thead"> <tr> <th rowspan="1" class="thh"> <span class="tn">收貨人</span> </th> <th rowspan="1" class="thh"> <span class="tn">所在地區(qū)</span> </th> <th rowspan="1" class="thh"> <span class="tn">詳細地址</span> </th> <th rowspan="1" class="thh"> <span class="tn">郵編</span> </th> <th rowspan="1" class="thh"> <span class="tn">電話/手機</span> </th> <th rowspan="1" class="thh"> <span class="tn">操作</span> </th> <th rowspan="1" class="thh"> <span class="tn">設(shè)置</span> </th> </tr> </thead> <tbody class="table-tbody"> <tr class="item" v-for="(v,i) in addressList"> <td class="tdd"> <span class="ti"> <em class="tt">{{v.name}}</em> </span> </td> <td class="tdd"> <span class="ti"> <em class="tt">{{v.address}}</em> </span> </td> <td class="tdd"> <span class="ti"> <em class="tt">{{v.detailAddress}}</em> </span> </td> <td class="tdd"> <span class="ti"> <em class="tt">{{v.zipCode}}</em> </span> </td> <td class="tdd"> <span class="ti"> <em class="tt">{{v.phone}}</em> </span> </td> <td class="tdd"> <span class="ti"> <div class="handle"> <a href="javascript:;" class="a-chg">修改</a> <i class="line">|</i> <em class="i-del">刪除</em> </div> </span> </td> <td class="tdd"> <span class="ti"> <em class="set-def cur" v-if="v.isDefault">默認地址</em> <em class="set-def" v-else @click="setDefault(i)">設(shè)為默認</em> </span> </td> </tr> </tbody> </table> </div> </div>
js功能
//地址管理 const vueAddress = new Vue({ el: '#vue-address', data(){ return{ addressList: [], //地址列表 } }, created(){ this.getAddressJson(); }, methods:{ //獲取地址列表數(shù)據(jù) getAddressJson(){ let url = 'json/addressTest.json'; axios.get(url) .then(response =>{ this.addressList = response.data.list; }) .catch(error => { console.log(error) }) }, //設(shè)置默認地址 setDefault(i){ const addressList = this.addressList; addressList.forEach((item, index) => { item.isDefault = index == i; }); addressList.splice(0, 0, ...addressList.splice(i, 1)); } } });
如有發(fā)現(xiàn)問題,可留言哦~
具體案例,可訪問本人github:https://github.com/xiexikang/vue-setDefaultAddress
總結(jié)
到此這篇關(guān)于基于vue.js仿淘寶收貨地址并設(shè)置默認地址的案例分析的文章就介紹到這了,更多相關(guān)vuejs設(shè)置默認地址內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3實現(xiàn)LuckSheet在線預覽Excel表格
在前端開發(fā)中預覽Excel文件是常見的需求之一,本文將介紹如何使用Vue.js框架以及兩個優(yōu)秀的Excel庫——LuckyExcel和Luckysheet,來實現(xiàn)Excel文件在線預覽功能,希望對大家有所幫助2023-11-11如何利用VUE監(jiān)聽網(wǎng)頁關(guān)閉并執(zhí)行退出操作
這篇文章主要給大家介紹了關(guān)于如何利用VUE監(jiān)聽網(wǎng)頁關(guān)閉并執(zhí)行退出操作的相關(guān)資料,因為項目中需求,瀏覽器關(guān)閉時進行一些操作處理,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下2023-08-08Vue項目的網(wǎng)絡(luò)請求代理到封裝步驟詳解
這篇文章主要介紹了Vue項目的網(wǎng)絡(luò)請求代理到封裝步驟,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04vue3.x中useRouter()執(zhí)行后返回值是undefined問題解決
這篇文章主要給大家介紹了關(guān)于vue3.x中useRouter()執(zhí)行后返回值是undefined問題的解決方法,文中通過代碼示例介紹的非常詳細,對大家學習或者使用vue3.x具有一定的參考借鑒價值,需要的朋友可以參考下2023-09-09