溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

vue3.0 CLI - 2.2 - 組件 home.vue 的初步改造

發(fā)布時(shí)間:2020-09-18 10:27:49 來源:腳本之家 閱讀:127 作者:nDos 欄目:web開發(fā)

我的 github 地址 - vue3.0Study - 階段學(xué)習(xí)成果都會(huì)建立分支。

helloworld.vue 都挪到 about 路由當(dāng)中。

<template><div class="about"><HelloWorld msg="vue 官方相關(guān)資料的鏈接"/></div></template>
<script>
import HelloWorld from '@/components/HelloWorld.vue'
export default { name: 'about', components: { HelloWorld } }
</script>

下面我們開始整理玩轉(zhuǎn) home.vue,后臺(tái)數(shù)據(jù)使用 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 組件有了兩個(gè)屬性: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>

這個(gè)改造過程比較簡(jiǎn)單,就不多介紹。也建立一個(gè) git 分支上傳。

總結(jié)

以上所述是小編給大家介紹的vue3.0 CLI - 2.2 - 組件 home.vue 的初步改造,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI