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 项目结构 及相应作用

猜你喜欢

转载自www.cnblogs.com/xiaozhu-zhu/p/11946845.html