前端

创建日期:2024-06-21
更新日期:2024-12-06

编译开发

1、安装yarn。

npm设置淘宝镜像:npm config set registry https://registry.npm.taobao.org/

安装yarn:npm install -g yarn

yarn设置淘宝镜像:yarn config set registry http://registry.npm.taobao.org/

2、运行前端。

依次运行:yarn install、yarn run serve。

3、浏览器访问:http://localhost:1888/#/login

账号:admin 密码:admin。

发布项目

1、执行yarn run build,生成项目。

2、将dist文件夹中的内容拷贝到nginx-1.21.1/html/文件夹。

3、编辑conf/nginx.conf,配置反向代理。

server {

    listen       *:8081;

    server_name  localhost;

       location / {

        root   html;

        index  index.html index.htm;

       }

       location ^~ /api/ {

              proxy_pass http://localhost:80/;

       }

}

4、在浏览器中访问:http://localhost:8081

常见问题

1、运行yarn install可能会提示缺少python2。

解决方法:安装python2,复制python.exe为python2.exe。

2、未能加载 Visual C++ 组件“VCBuild.exe”。

解决方法:管理员权限运行:npm install ~-~-global ~-~-production windows-build-tools

3、菜单管理增加传参数功能。

编辑文件src\router\avue-router.js,添加以下代码。

// 是否有参数

const query = {};

if (path.includes('?')) {

  const parts = path.split('?');

  parts[1].split('&').forEach(n => {

    if (!n.includes('=')) {

      return;

    }

    const params = n.split('=');

    query[params[0]] = params[1];

  });

  path = parts[0];

  component = 'views' + path;

}

//是否有子路由

const isChild = children.length !== 0;

const oRouter = {

  path : path,

  query : query,

  component(resolve) {

    // 判断是否为首路由

    if (first) {

      require(['../page/index'], resolve)

      return

在页面上获取参数:

this.$route.query.abc

4、npm install报错:Error: EPERM: operation not permitted, rename 'package.json.1394745013' -> 'package.json'。

执行npm install –no-bin-links。

5、Uncaught TypeError: $actualApply is not a function。

全部错误

Uncaught TypeError: $actualApply is not a function
    at eval (eval at callBindBasic (index.js:20:7), <anonymous>:1:1)
    at callBindBasic (index.js:20:7)
    at callBind (index.js:17:18)
    at <stdin> (callBound.js:12:20)
    at __require (callBound.js:3:49)
    at callBound.js:22:16

call-bind 由 1.0.7 自动升级到1.0.8导致的,在package.json中锁定版本到1.0.7即可。

{
 "resolutions": {
  "call-bind": "1.0.7"
 }
}

注意:该配置仅对yarn生效。