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>
相关推荐
zhoxier5 小时前
elementui el-select 获取value和label 以及 对象的方法
javascript·vue.js·elementui
四岁半儿9 小时前
vue,H5车牌弹框定制键盘包括新能源车牌
前端·vue.js
HANK14 小时前
KLineChart 绘制教程
前端·vue.js
Juchecar14 小时前
Naive UI 学习指南 - Vue3 初学者完全教程
前端·vue.js
尝尝你的优乐美15 小时前
封装那些Vue3.0中好用的指令
前端·javascript·vue.js
chxii15 小时前
5.4 4pnpm 使用介绍
前端·javascript·vue.js
好好好明天会更好15 小时前
Vue 中 slot 的常用场景有哪些
前端·vue.js
VOLUN16 小时前
PageLayout布局组件封装技巧
前端·javascript·vue.js
anyup16 小时前
🔥 🔥 为什么我建议你使用 uView Pro 来开发 uni-app 项目?
前端·vue.js·uni-app
听风的码18 小时前
Vue2封装Axios
开发语言·前端·javascript·vue.js