这个问题困扰了我2天的时间。几乎看完了所有的文档。网上各种配置,各种说法,这里做一个统一的归纳汇总。
这里说明一下,调试是调试,打包是打包,谁的问题,就看谁。
调试的问题请看 uniapp跨域的问题 的文章,在我的列表里面找。
下面说,当界面出现这个原因的解决方法。
先说uniapp的配置,其实uniapp的配置有2种方案,很多人都混用了。
先看程序里面调用的地方,这里就一种写法
async setData() {
this.A = "okok";
console.log("545456565");
// this.B = "true";
// this.C = ['你好', '世界'];
await uni.request({
url: 'api/demo/get',
header: {
},
method: 'GET',
data: {},
success: res => {
console.log(res);
this.D=res.data;
},
fail: () => {},
complete: () => {}
});
},
uniapp的配置,第一种:
1.H5这里可以不用配置任何东西
2.源码视图这里,这样配置
,
"h5" : {
// "router" : {
// "mode" : "hash",
// "base" : "/"
// },
"devServer" : {
"https" : false,
//"port" : 8081,
"disableHostCheck" : true,
"proxy" : {
"/api" : {
"target" : "http://192.168.1.101:8888/api",
"changeOrigin" : true,
"secure" : true,
"pathRewrite" : {
"^/api":"/"
}
}
}
}
}
uniapp的配置,第二种:
1.同理,H5这里可以不用配置任何东西
2.源码视图这里,这样配置
"h5" : {
// "router" : {
// "mode" : "hash",
// "base" : "/"
// },
"devServer" : {
"https" : false,
//"port" : 8081,
"disableHostCheck" : true,
"proxy" : {
"/api" : {
"target" : "http://192.168.1.101:8888",
"changeOrigin" : true,
"secure" : true,
"pathRewrite" : {}
}
}
}
}
配置好后,现在点击发行按钮,生成网站,效果如下
把这2个文件复制一下
下面是重中之重
下面是重中之重
下面是重中之重
下载nginx,我这里是nginx-1.20.2版本
下面是解压后,原始状态
这是我配置的nginx
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 808;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
try_files $uri $uri/ /index.html;
root D:/dist/;
index index.html index.htm;
}
# 配置与后端服务器地址的映射
location ^~ /api/ {
proxy_pass http://192.168.1.101:8888;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
第一个是端口号,第二个是网站的路径,把刚才的文件复制进去,
最后的面IP地址一定要看清楚,我的api接口是:
http://192.168.1.101:8888/api/demo/get
在网站输入地址:http://localhost:808/index.html
最后大功告成!!
文章来源:https://www.toymoban.com/news/detail-491788.html
来源:uniapp打包H5出现Please enable JavaScript to continue_please enable javascript to continue.-CSDN博客文章来源地址https://www.toymoban.com/news/detail-491788.html
到了这里,关于uniapp打包H5出现Please enable JavaScript to continue的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!