Category Archives: JavaScript

[Solved] el-tree setCheckedNodes Error: undefined (reading setCheckedNodes)

Summary:

Today, there is a requirement to write an EL tree in the sub-component (pop-up window) because it needs to be echoed, that is, once you click in, there will be the last checked one.

By checking the document, I think setcheckednodes are the most suitable. Then I click in and show it. My first reaction is to call the following method when mounting

setCheckedNodes() {
    this.$nextTick(() => {
        this.$refs.tree.setCheckedNodes(this.selectedAssign);
    });
},

Codes to report errors:

(spring window subassembly)

<template>
  <div class="dialog">
    <el-dialog
      title="权限分配"
      :visible.sync="dialogVisible"
      width="45%"
      top="8vh"
      ref="tk"
      :before-close="dialogClose"
    >
      <div class="dialog-mid">        
        <div class="online-detail">
          
          <div class="od-content">
            <div class="select-box">
              <div class="all-select">
                <div class="all-tit"><span></span></div>
                <div class="all-con">
                  <el-tree
                    :data="assignData"
                    show-checkbox
                    default-expand-all
                    node-key="id"
                    ref="tree"
                    :highlight-current="true"
                    :props="defaultProps"
                    @check-change="checkChange"
                  >
                  </el-tree>
                </div>
              </div>
            </div>            
          </div>
        </div>
        <div class="foot-botton">
          <el-button type="primary" @click="open">提交修改</el-button>
          <el-button @click="dialogClose">取消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ["dialogVisible"],
  data() {
    return {      
      assignData: [
        {
          id: 1,
          label: "1",
          children: [
            {
              id: 101,
              label: "101",
            },
            {
              id: 102,
              label: "102",
            },
          ],
        },
        {
          id: 2,
          label: "2",
          children: [
            {
              id: 201,
              label: "201",
            },
            {
              id: 202,
              label: "202",
            },
            {
              id: 203,
              label: "203",
            },
            {
              id: 204,
              label: "204",
            },
            {
              id: 205,
              label: "205",
            },
          ],
        },
        {
          id: 3,
          label: "3",
          children: [
            {
              id: 301,
              label: "301",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      selectedAssigns: [
         {
           id: 1,
           label: "1"
         },
         {
           id: 101,
           label: "101",
         },
         {
           id: 102,
           label: "102",
         },
      ],
    };
  },
  methods: {
    dialogSure() {
      this.$emit("dialogSure");
    },
    dialogClose() {
      this.$parent.dialogClose();
    },
    open() {
      this.$confirm("This action will change the privileges of this user, do you want to continue?" , "prompt", {
        confirmButtonText: "YES",
        cancelButtonText: "NO",
        type: "warning",
      })
        .then(() => {
          // this.dialogVisible = false;
          this.dialogSure();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "Modified Canceled",
          });
        });
    },

  

    

    setCheckedNodes() {    
      this.$nextTick(() => {
          console.log(this.$refs.tree,"this.$refs.tree");
          this.$refs.tree.setCheckedNodes(this.selectedAssigns);
      });
    },

    resetChecked() {
      this.$refs.tree.setCheckedKeys([]);
    },
  },
  mounted() {
    // Set the screen height to 90%
    this.$refs.tk.$el.firstChild.style.height = "70%";
    this.setCheckedNodes(); // ready to be called at the time of the popup mount will be able to click in and have a display back, but there is an error, 148 print out the result is undefined
    // this.$nextTick(() => { // Go online and check what others have written and say to use this.$nextTick when mounting.
    //   this.setCheckedNodes();
    // });
  },
};
</script>

<style scoped>

</style>

I thought I could call it when the pop-up window was mounted, and there was an echo when I clicked it, but there was an error, and the result printed out by 148 was undefined.

The error information is shown in the figure:

Seeing such error reporting experience tells me that when I execute this method, the dom of the pop-up window has not been created, and I can’t find this tree, but it’s strange that I clearly wrote this in this method$ Nexttick (this.$nexttick function can make the methods in it run after the DOM is created), and any operations are in this$ Nexttick.

Check others’ writing methods on the Internet and say you want to use this$ Nexttick is written when it is mounted. Then there is the section of code commented out in the mount, but it still reports an error, and the same error is reported.

I guessed that the DOM of the popup window was created after clicking to open the popup window, so I opened the popup window in the parent component in the method this.dialogVisible = true; and then went to call the setCheckedNodes method

How to call it? There is a very simple way to write the method of the parent component calling the child component, which is to give a ref= “dialog” on the child component

For example:

<Dialog :dialogVisible="dialogVisible" @dialogSure="dialogSure" ref="dialog"></Dialog>

Then call the method of the sub component in the method of opening this pop-up window: //selectedAssign is the starting array, which can be passed from the parent component

handleAssign(row,selectedAssign) {
    //selectedAssign is the starting array, which can be passed from the parent component
      this.dialogVisible = true;
      this.$refs.dialog.setCheckedNodes(selectedAssign);
},

Finally, save, refresh and re run, there will be no error, and there will be starting data.

[Solved] HBuilder Error: Cannot read property ‘forceUpdate‘ of undefined

Using the project developed by HBuilderX, WeChat develop tool report an error:

Cannot read property ‘forceUpdate’ of undefined

The solution is shown in the figure:

In the project directory, find manifest.json – WeChat applet configuration – configure “WeChat applet AppID”

Open the developer tool, view the corresponding appid, fill in the upper part, and refresh the developer tool.

If you continue to report this error, restart hbuildx and wechat developer tools after configuration, and re run the project.

 

core-js/modules/es.error.cause.js [How to Solve]

Reason: the installed version of core-js is too old and needs to be replaced with a newer version.

Solution:
1 Delete original version

 npm rm -rf node_modules  

2. install the latest version

npm install core-js@latest

Note:
you cannot directly install a new version. You must first delete the original version dependency, and then install a new version to avoid errors!

[Solved] vue error: error Component name “School“ should always be multi-word vue/multi-word-component-names

Error details:

error Component name “School” should always be multi-word vue/multi-word-component-names

Cause: when checking the syntax, the non-standard naming is regarded as a syntax error.

Solution: turn off syntax checking

Add the following codes in vue.config.js:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave:false /*Turn off syntax checking*/
})

[Solved] ERROR in ./node_modules/element-ui/lib/theme-chalk/fonts/element-icons.ttf

Problem Description:

Error reporting of global element introduction in Vue project based on scaffold development

Install according to the official document of element

npm i element-ui -S

Import main.js and use

//Import element

import ElementUI from ‘element-ui’

import ‘element-ui/lib/theme-chalk/index. css’

Vue. use(ElementUI)

Errors are reported as follows

Vscode terminal error


Web page error

Solution:

The problem was eventually found to be that the ‘ ‘ symbol in the font file was not recognized.

The conversion needs to be done with file-loader

Add the configuration to webpack.config.js

{
        test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
        loader: 'file-loader'
}

Add location as follows

Restart, problem solved

[Solved] Vue3 Error: error Delete `··` prettier/prettier

vue3 project error: error Delete `··` prettier/prettier

Run

npm  run  lint --fix

It depends on what tool is used. If you use yarn or pnpm, you can replace it

If present

Open package.json file, and view the configuration

For example, the configuration of my project is as follows

The command to run is:

npm run lint:eslint --fix 

Then restart the project

Supplement:

Found that error Delete `——–␍⏎` prettier/prettier is too much when using webstorm, and every time I modify the code, this error will appear, which is troublesome to operate. So choose to close the Prettier code specification directly
Just configure it in the rules in eslintrc.js

'prettier/prettier': 'off'

[Solved] gyp ERR! stack Error: Could not find any Python installation to use

Header error prompt

gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON

Tail error prompt

gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:330:47)
gyp ERR! stack     at PythonFinder.runChecks (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:159:21)
gyp ERR! stack     at PythonFinder.<anonymous> (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:248:16)
gyp ERR! stack     at PythonFinder.execFileCallback (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:294:16)
gyp ERR! stack     at exithandler (node:child_process:406:5)
gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:418:5)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
gyp ERR! stack     at onErrorNT (node:internal/child_process:478:16)
gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
gyp ERR! System Windows_NT 10.0.22000
gyp ERR! command "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd G:\aidex\font-end\aidex-ui\node_modules\deasync
gyp ERR! node -v v16.15.1
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok

Solution:

NPM installation

npm i -g node-gyp

Yarn installation

yarn global add  node-gyp

 

[Solved] Vue-cli Error: Module not found: Error: Can‘t resolve ‘vue-router ‘

Error Messages:

Compiled with problems:X
ERROR in ./src/router/index.js 2:0-23
Module not found: Error: Can’t resolve ‘vue ‘ in ‘D:\F\XX\project-SPH\app\src\router’

ERROR in ./src/router/index.js 3:0-36
Module not found: Error: Can’t resolve ‘vue-router ‘ in ‘D:\F\XX\project-SPH\app\src\router’

ERROR in ./src/router/index.js 8:0-36
Module not found: Error: [CaseSensitivePathsPlugin] `D:\F\XX\project-SPH\app\src\pages\search\index.vue` does not match the corresponding path on disk `Search`.


The incorrect index.js code at this point is as follows:

// Where to configure routing
import Vue from 'vue ';
import VueRouter from 'vue-router ';//Using the plug-in
Vue.use(VueRouter);
//Introduction of routing components
import Home from '@/pages/Home'
import Search from '@/pages/search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
//configure routing
export default new VueRouter({
//configure routing
    routes:[
    {
        path : "/home",
        component:Home
    },{
        path: " /search",
        component:Search
    },{
        path: " /login",
        component:Login
    },{
        path: " /register",
        component:Register
    }
    ]
})

Process

At first, it was because Vue-router could not be installed. I suspected that Vue-router was not installed properly.

After an afternoon of Googling to find the cause, I decided to look at the code myself to see what the error meant. There are a total of 3 code: all point to the index.js file.

The first place: pointing to Search, I looked at the reference Search place, found written in lower case.

The second place: the reference to vue and vue-router, after careful observation, I found that I wrote an extra space.

After correction, it can be run again without any error.

[Solved] React Startup Error at the First time :SyntaxError: Unexpected token

[react] prompt syntaxerror: unexpected token

1. background

Use react scaffold to build the project

  • Install globally: npm i -g create-react-app
  • create-react-app hello-react
  • Go to the project folder: cd hello-react
  • Start the project: npm start

When executing npm start, an error occurred, please check the node version.

 

2. problem-solving

  • The investigation found that it was caused by the node version.
  • execute node -v ;

  • react-app requires node version greater than 14
  • execute nvm use 14;

  • Just restart.

[Solved] express-jwt Error: Error: jwt is not a function

Problem Description:

Express JWT is not a function

Cause analysis:

The express JWT I installed is version 7.7.5, and the usage has changed.

https://www.npmjs.com/package/express-jwt

Check the official documents for the latest usage

Solution:

1. import

var { expressjwt:jwt } = require("express-jwt")

2. registration

app.use(jwt({ 
secret: 'shhhhhhared-secret', algorithms: ['HS256'] 
}).unless({ path:[/^\/api\//] }))

.unless ({specify the path without access permission with regular})

Or another method, directly add the unique protected path address as a parameter:

app.use("/api", jwt({ 
secret: "shhhhhhared-secret", algorithms: ["HS256"] 
}));

3. user data

Once parsed successfully, the user data contained in the Token will be automatically mounted on req.auth

// This is an API interface with permissions
app.get('/admin/getinfo', function (req, res) {
  // TODO_05: use req.auth to get the user information and use the data property to send the user information to the client
  console.log(req.auth);
  res.send({
    status: 200,
    message: 'User information retrieved successfully! ,
    data: req.auth// the user information to be sent to the client
  })
})