欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-08-28 10:47:46
我的 github 地址 - vue3.0study - 阶段学习成果都会建立分支。 helloworld.vue 都挪到 about 路由当中。

我的 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 分支上传。

总结

以上所述是小编给大家介绍的vue3.0 cli - 2.2 - 组件 home.vue 的初步改造,希望对大家有所帮助