vite中没有require,require是在webpack中使用的
可以使用import先导入图片,再使用
例如
import deviceImg from '@/static/images/device.png'
然后再组件里边images标签里边使用,例如
<image class="img" :src="deviceImg"></image>
或者是使用
new URL('静态路径', import.meta.url).href
例如
const deviceList = ref([
{
id: 'l002',
tag: 'device',
ico: new URL('@/static/images/device01.png', import.meta.url).href,
name: '水泵0035、水泵0056',
flow: '瞬时流量:10方/小时',
share: '已分享5人',
status: 'running',
statusName: '运行中',
},
{
id: 'l503',
tag: 'project',
ico: new URL('@/static/images/project.png', import.meta.url).href,
name: '北京市智慧农业产业示范园',
flow: '瞬时流量:13方/小时',
share: '已分享2人',
status: 'fault',
statusName: '已故障',
},
])
在组件中使用
![在这里插入图片描述](https://img-blog.csdnimg.cn/37f307ecbe6241e7a30c12358ea1f28e.png)
我这里是在uniapp中使用的,在vue项目中同理