vue项目不能直接访问本地资源,因为创建了node服务器,服务器上不能直接访问客户端的文件,而html文件可以直接访问本地资源,因为这个html本来就是本地打开的 。
可以把本地资源在nginx上配成服务
只修要修改nginx.conf文件就行
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream big_server_com {
server 192.168.0.48:80 weight=3;
server 192.168.0.48:8080 weight=3;
}
server {
listen 8080;
server_name localhost;
location / {
root C:\\Users\\Administrator\\Desktop\\pc\\zhinenganjianahead\\npback\\dist;
index index.html index.htm;
}
}
server {
listen 80;
server_name localhost;
location / {
root C:\\Users\\Administrator\\Desktop\\*******\\*********;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
配置好重启一下nginx即可
在vue项目中直接访问ip+端口号即可
如: <img :src="'http://localhost/'+url" alt="">
data(){
return{
url:"8J0D6C5GAJ000031/20230516/123@&1233.jpg",
}
}