vite项目引入本地图片作为css背景图片

2023-01-02  本文已影响0人  苍老师的眼泪

vite.config.js

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "/src"),
      "~@": path.resolve(__dirname, "/src"),
    },
  },
})

测试:

<template>
  <div class="test">
    test
  </div>
</template>

<script setup>
</script>

<style lang="less" scoped>
    .test {
        width: 100%;
        height: 100%;
        background-image: url('@/assets/positions.jpeg');
    }

</style>
上一篇 下一篇

猜你喜欢

热点阅读