vue3.0 CLI 真小白一步一步入手全教程系列:https://www.cnblogs.com/ndos/category/1295752.html
我的 github 地址 - vue3.0Study - 階段學習成果都會建立分支。
==========================
helloworld.vue 都挪到 about 路由當中。
<template><div class="about"><HelloWorld msg="vue 官方相關資料的鏈接"/></div></template>
<script>
import HelloWorld from '@/components/HelloWorld.vue'
export default { name: 'about', components: { HelloWorld } }
</script>
下面我們開始整理玩轉 home.vue,后台數據使用 https://www.apiopen.top/journalismApi
先貼出 script 代碼:
export default { name: 'home', data: function (){ return { navs: {}, tts:[] } }, created: function (){ fetch('https://www.apiopen.top/journalismApi') .then(v=>v.json()) .then(v=>{ console.log(v.data); this.tts = v.data.toutiao; this.navs = v.data; }); } }
home.vue 組件有了兩個屬性:navs 和 tts 屬性。在 template 中使用如下代碼:
<template> <div class="home"> <div class="nav"> <div v-for="(value, key, index) in navs" :key="index"> {{key}} </div> </div> <ul> <li v-for="(tt,index) in tts" :key="index"> {{tt.title}} </li> </ul> </div> </template>
這個改造過程比較簡單,就不多介紹。也建立一個 git 分支上傳。