uniapp vue3 静态图片引入

方法一 从新定义路径 一定看好你图片的路径

代码
复制代码
<template>
    <div class="main">
        Main
        <img :src="getImg()" alt="">
    </div>
</template>

<!-- 方式一
// <script setup>
// let imgName = 'logo.png'
// const getImg = () => {
//     return new URL(`/static/${imgName}`, import.meta.url).href;
// }
// </script> -->

<!-- 方式二 -->
<script >
	export default {
		setup(){
			const imgName = 'logo.png'
			
			function getImg (){
				// 从新定义了一下图片路径  返回返回一下 
				return new URL(`/static/${imgName}`, import.meta.url).href;
			}
			return{
				imgName,
				getImg
			}
		}
	}

</script>

展示

方法二

代码
复制代码
<template>
	<div v-for="item in services.items" :key="item.icon">
		  <img :src="item.icon" />
		<p>{{item.label}}</p>
	</div>
</template>
<script setup>
	const services = {
		title: '园区服务',
		items: [{
				icon: '/static/logo.png',
				label: '招租发布',
				path: '/pages/index/index',
			},
			{
				icon: '/static/faxian.png',
				label: '手续办理',
				path: '/pages/index/index',
			},
		],
	};

</script>
展示
相关推荐
徐小夕7 小时前
我用 AI 撸了个开源"万能预览器":浏览器直接打开 Office、CAD 和 3D 模型
前端·vue.js·github
小码哥_常8 小时前
Flutter Android 延迟加载代码指南:提升应用性能的关键
前端
这是个栗子8 小时前
TypeScript(三)
前端·javascript·typescript·react
kvo7f2JTy8 小时前
基于机器学习算法的web入侵检测系统设计与实现
前端·算法·机器学习
北风toto8 小时前
前端CSS样式详细笔记
前端·css·笔记
nanfeiyan8 小时前
git commit
前端
前端精髓11 小时前
移除 Effect 依赖
前端·javascript·react.js
码云之上11 小时前
从一个截图函数到一个 npm 包——pdf-snapshot 的诞生记
前端·node.js·github
码事漫谈11 小时前
AI提效,到底能强到什么程度?
前端·后端
IT_陈寒11 小时前
React hooks依赖数组这个坑差点把我埋了
前端·人工智能·后端