vue-cli 3版本沒有static文件夾,本地文件應放在哪兒,如何引用


2.x版本目錄:

 

 

 

3.0版本:

 

 

 

 

原來放在static下的文件,現在應該放在public文件夾下
2.x 寫法:

methods: {
  fetchData () {
    let _this = this
    this.$http.get('/static/data/article.json').then(res => {
      _this.htmlText = res.data
    }).catch(err => {
      console.log('22222:', err)
    })
  }
}

 


3.0寫法:

1 fetchData () {
2     // this.htmlText = article[this.$route.query.id].content
3   let _this = this;
4     this.$http.get('/data/article.json').then(res => {
5     _this.htmlText = res.data
6   }).catch(err => {
7     console.log('222222:', err)
8   })
9 }

 


 如果json文件里有圖片路徑里不用加 public 

1 <img src=\"../../public/img/details06_3.png\" alt=\"\">


改為:

1 <img src=\"../../img/details06_3.png\" alt=\"\">

 

cli3.0 項目結構 及相應作用

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM