uniapp打包H5出现Please enable JavaScript to continue

这个问题困扰了我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

最后大功告成!! 

来源:uniapp打包H5出现Please enable JavaScript to continue_please enable javascript to continue.-CSDN博客

  • 5
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

故里2130

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值