Day19 vue.js之我的专案显示

延续昨日
今天从我的专案开始
老样子先新增一个project.vue
再来去加入新的path
然後先把home.vue的程序码直接贴过来
再来做一点小修正
https://ithelp.ithome.com.tw/upload/images/20211001/20141007yxgT3lahmG.png

这样乍看之下是对的因为目前就2篇文章然後2篇都是邦乔飞发的https://ithelp.ithome.com.tw/upload/images/20211001/20141007e1KbqftCz8.png

但是实际上我们还缺少了一个步骤就算抓出所有文章帐号是属於邦乔飞的
然後把这些文章列出来

async mounted(){
      let articles =await axios.get(`${this.db_api}`+"articles?useraccount=sa")
     this.projects=articles.data
     let user=sessionStorage.getItem('user-info')
     this.useraccount=JSON.parse(user).id
     this.username=JSON.parse(user).username
   
    
   }

基本上就只动了一点点
可以看到目前是这样
https://ithelp.ithome.com.tw/upload/images/20211001/20141007y9anyWE6RO.png

接下来将写死的参数改掉

async mounted(){
      let articles =await axios.get(`${this.db_api}`+"articles?useraccount="+`${this.useraccount}`)
     this.projects=articles.data
     let user=sessionStorage.getItem('user-info')
     this.useraccount=JSON.parse(user).id
     this.username=JSON.parse(user).username
   
    
   }

https://ithelp.ithome.com.tw/upload/images/20211001/20141007l0mUhlboHz.png

没想到这样竟然没有显示任何东西
真是太奇怪了
Debug 半天才发现原来是顺序问题

async mounted(){
  
   let user=sessionStorage.getItem('user-info')
   this.useraccount=JSON.parse(user).id
   this.username=JSON.parse(user).username
   let articles =await axios.get(`${this.db_api}`+"articles?useraccount="+`${this.useraccount}`)
   this.projects=articles.data
  
 }

我要先接到session我的useraccount才会有值
接下来就来测试看看吧!!
登入一个之前创的帐号
https://ithelp.ithome.com.tw/upload/images/20211001/201410071Zp2wyFoSR.png
可以看到里面空无一物
再来就是新增专案
https://ithelp.ithome.com.tw/upload/images/20211001/2014100789ztHum1I5.png
再回去home列表确认有新增资料了
https://ithelp.ithome.com.tw/upload/images/20211001/20141007sUw6DbwWG7.png

最後再点回去project.vue里面看看
嘟嘟噜成功了只抓了该登入成员的专案资料
https://ithelp.ithome.com.tw/upload/images/20211001/20141007rj0fU4U0jy.png

好了今天被我自己的code搞了好长一段时间
我感觉自己的code不是很乾净 应该是我写程序的经验还不够
明天铁人赛第20天就来把修改文章的功能还有把code整理一下

我们明天见!!


<<:  Day16 Gin's Routing Structure And Context

>>:  DAY19 - 在win10家用版上安装Docker Desktop

企划实现(28)

使用自定义的listview 第一步:制作自己想要的listview格式 <?xml vers...

Day 18 - Tally String Times with Reduce

前言 JS 30 是由加拿大的全端工程师 Wes Bos 免费提供的 JavaScript 简单应用...

Day 27 初学者补给站 学习方向讨论

大家好~~欢迎来到第二十七篇 学习方向讨论 上一篇跟大家说到程序,如何自我学习,找寻方法,今天来讲别...

# Day 14 Cache and TLB Flushing Under Linux (Q&A - II)

今天来复习 cache 相关的知识! 首先可以参考一下这篇:Day.8 Cache 的基本原理 ca...

Day 08 借箸代筹(2):自动转型、运算子及其後

自动转型 续前文所述,当我们使用两个等号(==)作比较运算时,深受JavaScript「自动转型」的...