日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue 3.x 中使用ele-image时相对路径的图片加载失败

發(fā)布時(shí)間:2023/12/9 vue 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue 3.x 中使用ele-image时相对路径的图片加载失败 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

參考文檔: https://element.eleme.cn/#/zh-CN/component/installation

環(huán)境: Mac OS X 10.12

[zcm@ele 2]$node -v v12.6.0 [zcm@ele 3]$npm -v 6.9.0 [zcm@ele 4]$cnpm -v cnpm@6.1.0 (/usr/local/lib/node_modules/cnpm/lib/parse_argv.js) npm@6.10.2 (/usr/local/lib/node_modules/cnpm/node_modules/npm/lib/npm.js) node@12.6.0 (/usr/local/Cellar/node/12.6.0/bin/node) npminstall@3.22.1 (/usr/local/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js) prefix=/usr/local darwin x64 16.7.0 registry=https://r.npm.taobao.org[zcm@ele 6]$vue -V 3.9.2

創(chuàng)建項(xiàng)目:?vue?create?ele

cd?ele

cnpm?i

npm?run?serve

項(xiàng)目目錄結(jié)構(gòu)



安裝element:?vue?add?element
?

修改main.js

import Vue from 'vue'import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css';import App from './App.vue'Vue.use(ElementUI)Vue.config.productionTip = falsenew Vue({render: h => h(App), }).$mount('#app')

修改App.vue

<template><div id="app"><HelloWorld msg="Welcome to Your Vue.js App"/></div> </template><script> import HelloWorld from './components/HelloWorld.vue'export default {name: 'app',components: {HelloWorld} } </script><style> #app {font-family: 'Avenir', Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-align: center;color: #2c3e50;margin-top: 60px; } </style>

修改 ./components/HelloWorld.vue

<template><div class="hello"><h1>{{ msg }}</h1><div><img class="dlogo" :src="src" /><img class="dlogo" src="../assets/logo.png" /></div><div><el-image class="dlogo" :src="src"></el-image><el-image class="dlogo" src="@/assets/logo.png"></el-image><el-image class="dlogo" src="../assets/logo.png"></el-image><el-image class="dlogo" src="/images/logo.png"></el-image></div></div> </template><script>export default {name: 'HelloWorld',props: {msg: String},data: function () {return {src: require('@/assets/logo.png')// src: "../assets/logo.png"}},created (){// console.log(this.src);} } </script><!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> .hello {display: flex;flex-direction: column; }h3 {margin: 40px 0 0; } ul {list-style-type: none;padding: 0; } li {display: inline-block;margin: 0 10px; } a {color: #42b983; }.dlogo {border: 1px dashed red;height: 100px; } </style>

最終瀏覽器上運(yùn)行結(jié)果:

能正常顯示的圖片對(duì)應(yīng)的地址是:

總結(jié):

1. assets目錄下的資源文件在使用時(shí)要用require() 處理下,因?yàn)閣ebpack打包時(shí)路徑發(fā)生了變化!

2. 只有public下的文件,是原樣打包的!

?

?

總結(jié)

以上是生活随笔為你收集整理的vue 3.x 中使用ele-image时相对路径的图片加载失败的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。