Day17 vue.js 连接资料库显示文章

延续昨日
今天的目标是把首页的文章内容改成get资料库的文章内容
首先先去db.json 设定
我新增了一个 articles的schema
然後设一些资料(有一些栏位是之後会用到的 反正先设定)
https://ithelp.ithome.com.tw/upload/images/20210929/20141007cYe3Pw56hD.png

再来去home.vue 设定global db_api
接着在mounted里面调整一下

async mounted(){
  let user=sessionStorage.getItem('user-info')
  this.userid=JSON.parse(user).id
  this.username=JSON.parse(user).username

  let articles =await axios.get(`${this.db_api}`+"articles")
  this.projects=articles.data

}

我新增了2行程序码
//这个是get资料库中this.db_api+articles(http://localhost:3000/articles
)的值
let articles =await axios.get(${this.db_api}+"articles")

//这行是把原本的阵列 projects给替换成articles.data
this.projects=articles.data

甚麽意思呢先看看retrun data

data(){
   return{
      useraccount:"",
      username:"",
      db_api:global.db_api,
    //  专案资料

     projects:[
       {title:"铁人赛day6", person:"邦乔飞",content:"it铁人赛day6 \n今天连假还要打code \n我好累QQ",time:"2021/09/18",status:"进行中"},
       {title:"铁人赛day5", person:"邦乔飞",content:"it铁人赛day7 ",time:"2020/09/17",status:"已完成"},
       {title:"铁人赛day7", person:"邦乔飞",content:"it铁人赛day5 ",time:"2020/09/19",status:"未开始"},


     ]
   }
 },

原本的projects 阵列我有在里面的title person content 打东西现在替换成 articles.data的资料了
所以现在的projects会变成这样

[ {
      "title": "铁人赛day17",
      "person": "邦乔飞",
      "status": "未开始![https://ithelp.ithome.com.tw/upload/images/20210929/20141007JgtdjETNsE.png](https://ithelp.ithome.com.tw/upload/images/20210929/20141007JgtdjETNsE.png)",
      "content": "我好累我好累我好累我好累我好累喔",
      "time": "2020/02/08",
      "useraccount": "sa",
      "url": "",
      "swagger": "",
      "api": "",
      "api_val": "",
      "id": 1
    }]

至於网页则是这样(目前只有一笔文章)
https://ithelp.ithome.com.tw/upload/images/20210929/20141007ZxhC38eCVA.png

再来就可以把原本的projects给删除了
https://ithelp.ithome.com.tw/upload/images/20210929/20141007dzHF5XTIsK.png

没想到把资料给显示出来就花了这麽多的时间
明天就从新增专案开始吧!!
我们明天见!


<<:  Day 17手势识别GestureDectector

>>:  Day21-又给人贴标签 Labels and Selectors

Day 04 Compoent及路由介绍

由於笔者当初是用ASP.NET Core API + Blazor Server,所以会以Blazo...

Day 20 - 浅谈气候变迁与净零碳排

过去几个月, 各大商业杂志的封面不约而同地都出现同样主题的内容, 即"零碳",...

资安即国安,台湾需要更多的CISSP!

安全是品质的一部分 在过去的二十多年中,透过提供IT解决方案帮客户解决问题一直是我的使命。一路走来,...

为什麽端到端加密应成为企业的重要事项?

近年来,端到端加密已变得非常流行,尤其是在消费者消息传递应用程序市场中。Signal、Telegra...

Snapshot API测试

接下来照着永丰提供的github, 下一个要使用到的是快照-Snapshot的部分, 简单来说就是当...