1、如果这些产品图片文件“万年不变”,放在 /static 目录里,(不需要使用require将这些图片作为模块来引用)

var products = [{
  img: '/static/img/products/1.png',
  name: 'Product 1'
}, {
  img: '/static/img/products/2.png',
  name: 'Product 2'
}, {
  img: '/static/img/products/3.png',
  name: 'Product 3'
}, {
  img: '/static/img/products/4.png',
  name: 'Product 4'
}]

2、Vue实例数据的数组中只会保存图片文件路径,通过webpack打包不会将图片拷贝到dist目录中,所以本着模块化的思想下,应该用require来引用

var products = [{
  img: require('@/assets/products/1.png'),
  name: 'Product 1'
}, {
  img: require('@/assets/products/2.png'),
  name: 'Product 2'
}, {
  img: require('@/assets/products/3.png'),
  name: 'Product 3'
}, {
  img: require('@/assets/products/4.png'),
  name: 'Product 4'
}] 

 

相关文章:

  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2021-12-11
  • 2021-06-25
  • 2021-11-06
  • 2021-11-19
相关资源
相似解决方案