How does webpack handle the problem of loading resource files introduced through `js`?

related configuration:

:/var/website/test
:
compiled
source
    components
        public
            public.vue
    static
        image
            test.png
    plugins
    // ...
static

suppose that in a source/components/public/public.vue file, a file is introduced through js :

<template>
    <section>
        <img ref="test" src="" class="image">
    </section>
</template>
<script>
export default {
    name: "" , 
    mounted () {
        this.$refs.test.src="../../static/image/test.png";
    }
};
</script>

webpack after being packaged, the resource cannot be accessed!

how does webpack handle the loading of resource files introduced through js ?

Apr.15,2021

first import then use

import src from '../../static/image/test.png';

export default {
  name: '',
  mounted() {
    this.$refs.test.src = src;
  }
};

other resources such as pictures introduced by webpack must also be require or import (which will eventually be converted to require)

Menu