遇到几个前端小问题

文章封面

babel 问题

babel是负责转换ES 新版本语法到老版本js上的。 比如解构语法 ... 程序有如下报错

Syntax Error: Unexpected token

   8 |     let data_ = [];
   9 |     data.forEach(d => {
> 10 |       let d_ = {...d};
     |                 ^
  11 |       //产品名称
  12 |       if(d_.hasOwnProperty('productNo')){
  13 |         d_.productName = product.getProductNameByProductNo(d_.productNo);

解决方法

yarn add -D babel-plugin-syntax-jsx
yarn add -D babel-plugin-transform-runtime
yarn add -D babel-plugin-transform-vue-jsx
yarn add -D babel-preset-env
yarn add -D babel-preset-stage-2 

前端工程根目录建立.babelrc,写入如下内容

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": [
       "transform-runtime",
       "transform-vue-jsx"
      ]
}

postcss的问题

image

Module build failed: Error: No PostCSS Config found in: E:\CODE\xxxxxx

新建.postcssrc.js文件,写入如下内容

module.exports = {
  "plugins": {
    "postcss-import": {},
    "postcss-url": {},
    // to edit target browsers: use "browserslist" field in package.json
    "autoprefixer": {}
  }
}

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0