一、若是這些產品圖片文件「萬年不變」,放在 /static 目錄裏,(不須要使用require將這些圖片做爲模塊來引用)webpack
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' }]
二、Vue實例數據的數組中只會保存圖片文件路徑,經過webpack打包不會將圖片拷貝到dist目錄中,因此本着模塊化的思想下,應該用require來引用web
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' }]