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' }]