官网地址:https://cli.vuejs.org/zh/guide/html-and-static-assets.html#url-%E8%BD%AC%E6%8D%A2%E8%A7%84%E5%88%99

最近学习vue3,在封装图片时需要传入路径,相对路径太麻烦,绝对路径报错,在官网看到这个特记录一下

 

<template>
  <div class="trait">
    <img :src="`${publicPath + sonUrl}`"/>
    {{sonUrl}}
  </div>
</template>

<script lang="ts">
import Vue from "vue";
export default Vue.extend({
  props: {
    sonUrl: String,
  },
  data() {
    return {
      publicPath: process.env.BASE_URL,
    };
  },
});
</script>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-11-28
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
相关资源
相似解决方案