Category Archives: Javasript

[Solved] Vue3 vite Error: Uncaught ReferenceError: require is not defined

when using vue3 + vite to build the background framework template, errors will be reported in vite according to some previous writing methods.

Require. In vue3 vite Context error

in vue2, use require Context to get all the files of a file, but an error is reported after using vite in vue3.

you need to use import meta.globEager("./modules/*.js")

process. env. XXXX related variable error

in vue2, use process env.XXXX to get environment variables

use iimport meta.env.XXXX solution

problems in subsequent construction shall be updated gradually

[Solved] Vuex error: Error in callback for watcher “function() {return this._data.$$state}”

this._data.$$ state

Error content: error in callback for watcher "function() {return this._data.$$state}"

I also encountered this problem and tried to solve it. You can check whether the routing array object is stored in vuex and whether the array is directly referenced in state. You may need to make a deep copy before using it– razor

Note: JS array is reference assignment by default, and vuex can only change the state through mutation or action, bell The warnlist of the Vue component modifies the value of vuex

 

[Solved] Vue+Django Project js error: Error in render: “TypeError: Cannot read properties of null (reading ‘id’)”

Error Messages:
Error in render: “TypeError: Cannot read properties of null (reading ‘id’)”
Solution:

this.allMenuLabel = response.data add results: this.allMenuLabel = response.data.results

[Solved] vue.config.js Error: cannot set property “preserveWhitespace” of undefined

vue.config.JS error cannot set property “preservewhitespace” of undefined

Recently, the webpack has been configured in the project. Because vue-cli4 needs to be in Vue config.JS file to complete the relevant configuration, so based on the principle of not making wheels, I went to the online CV method directly, but I found some problems in practice, and reported an error when the project was started cannot set property "preservewhitespace" of undefined

module.exports = {
    lintOnSave:false,
    chainWebpack: (config) =>{
        config.module
          .rule('vue')
          .test( /\.vue$/)
          .use('vue-loader')
          .tap((options) =>{
            options.compilerOptions.preserveWhitespace = true
            }
          )
    }
}

Print out the options option and find that there is no complier options option:

Because the Vue loader I configured here can’t be solved after surfing the Internet for an afternoon, and even some people have made such errors, I pointed the solution to the problem to the document. In the Vue loader document, I saw the option compileroptions :

Good guy, this option is empty by default, so we can’t add it directly below, so we modified the code:

const addOptions = {
  preserveWhitespace: true
}
module.exports = {
    lintOnSave:false,
    chainWebpack: (config) =>{
        config.module
          .rule('vue')
          .test( /\.vue$/)
          .use('vue-loader')
          .tap((options) =>{
            options.compilerOptions = addOptions
            console.log(options)
            }
          )
    }
}

Let’s print the Options options to see if they are added:

We can see that the options are added and the project starts normally. If you encounter similar problems, this option may be empty and cannot be added directly.

[Solved] Vue Error: NavigationDuplicated: Avoided redundant navigation to current location: “xxx”.

Duplicate route jump problem

Solution: In router folder index.js add the following code:

const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue axios Error: Uncaught (in promise) TypeError: Cannot convert undefined or null to object at Function.keys () at mergeConfig (axios.js:1308)

Problem: In VUE version 3.0.4, an error is reported when using axios
Uncaught (in promise) TypeError: Cannot convert undefined or null to object     at Function.keys (<anonymous>)     at mergeConfig (axios.js:1308)

 

Solution:
Reinstall axios:

npm install [email protected] --save

okay~

Component is missing template or render function [How to Solve]

I use the method in Vue element admin to solve the problem that clicking the same menu bar on the side bar does not refresh

// First register a route named `redirect`
<script>
export default {
  beforeCreate() {
    const { params, query } = this.$route
    const { path } = params
    this.$router.replace({ path: '/' + path, query })
  },
  render: function(h) {
    return h() // avoid warning message
  }
}
</script>

Using such a piece of code, an error is reported in my project, and I hide the render function,

However, there is still a warning. Although it does not affect the use, the warning still annoys me,

<template>
  <div>
  </div>
</template>
<script>
// Redirect page, other pages manually trigger a redirect to this page, this page and then return to the original page, in order to achieve the same route to refresh the page effect
export default {
  created() {
    const { params, query } = this.$route
    let { path } = params
    if(path instanceof Array) {
      path = path.join('/')
    }
    this.$router.replace({ path: '/' + path, query })
  },
  // render: function(h) {
  //   return h() // avoid warning message
  // }
}
</script>

In fact, it’s a very simple literal problem. I think Vue element admin is used like this. There is no error reported. I didn’t find Baidu,

Then I suddenly thought of adding a template, which was solved

[Solved] Found bindings for the following environments: Windows 64-bit with Node.js 8.x

The reason for this problem is that the node running on the current computer is inconsistent with the version required for the project

Before that, it was updated that there was a problem with node-sass
so CMD was used to update NPM rebuild node-sass
but an error was still found after startup
1. First check the running version node
open webstorm to view the running node version. The high version problem will lead to a bug

Using version 9 can reduce the problem of error reporting.

2. After checking that there is no problem, rebuild node-sass
Open CMD in the project directory:
enter the command: npm rebuild node-sass
and then update it: npm update

[Solved] Vue2.0 + webpack + SuperMap error: Module parse failed: Unexpected token (82:85)

Problem description

For projects created using Vue cli, SuperMap does not report errors

SuperMap reports an error for a project created using webpack

Configuration

npm -v 6.14.10

node -v v14.15.4

“webpack”: “^3.6.0”,

“@supermap/iclient-leaflet”: “^10.2.0”

Solution:

Change the webpack configuration file