vue动态引入静态资源

vue动态引入静态资源

静态资源位置( ../../assets/piecture/page404.jpg**)或者(** @/assets/piecture/page404.jpg**)**

错误引入方式

错误引入方式(一)

html 复制代码
<template>
  <div>
    <img :src="`../../assets/piecture/${page404_$}.jpg`" class="page-404" />
  </div>
</template>

<script>
export default {
  name: "NotFound",
  data() {
    return {
      page404_$: "page404"
    };
  }
};
</script>

错误引入方式(二)

html 复制代码
<template>
  <div>
    <img :src="page404Path" class="page-404" />
  </div>
</template>

<script>
export default {
  name: "NotFound",
  data() {
    return {
      page404Path: "../../assets/piecture/page404.jpg",
    };
  }
};
</script>

正确引入方式

正确引入方式(一)

javascript 复制代码
<template>
  <div>
    <img src="../../assets/piecture/page404.jpg" class="page-404" />
  </div>
</template>

<script>
export default {
};
</script>

正确引入方式(二)

html 复制代码
<template>
  <div>
    <img :src="page404Imply" class="page-404" />
  </div>
</template>

<script>
import page404Imply from "@/assets/piecture/page404.jpg";
export default {
  name: "NotFound",
  data() {
    return {
      page404Imply
    };
  }
};
</script>

正确引入方式(三)

html 复制代码
<template>
  <div>
    <img :src="page404" class="page-404" />
  </div>
</template>

<script>
export default {
  name: "NotFound",
  data() {
    return {
      page404: require("@/assets/piecture/page404.jpg"),
    };
  }
};
</script>

正确引入方式(四)

html 复制代码
<template>
  <div>
    <img :src="page404ImpAsync" class="page-404" />
  </div>
</template>

<script>
export default {
  name: "NotFound",
  data() {
    return {
      page404ImpAsync: "",
    };
  },
  created() {
    import("@/assets/piecture/page404.jpg").then((res) => {
      this.page404ImpAsync = res.default;
    });
  },
};
</script>
相关推荐
发呆的薇薇°3 小时前
vue3 配置@根路径
前端·vue.js
luoluoal3 小时前
基于Spring Boot+Vue的宠物服务管理系统(源码+文档)
vue.js·spring boot·宠物
luckyext4 小时前
HBuilderX中,VUE生成随机数字,vue调用随机数函数
前端·javascript·vue.js·微信小程序·小程序
yangjiajia1234566 小时前
vue3 ref和reactive的区别
前端·javascript·vue.js
诚信爱国敬业友善6 小时前
Vue 基础二(进阶使用)
前端·javascript·vue.js
努力小贼7 小时前
uni-app发起网络请求的三种方式
前端·javascript·vue.js·uni-app
LiuMingXin8 小时前
埋头苦干Vue3项目一年半,总结出了16个代码规范
前端·vue.js·面试
Aic山鱼9 小时前
Vue 3最新组件解析与实践指南:提升开发效率的利器
前端·javascript·vue.js
焦糖瓜子1239 小时前
Vue大屏展示列表向上循环滚动动画,requestAnimationFrame
vue.js