Tag Archives: View.js

[Solved] Error:Plugin/Preset files are not allowed to export objects, only functions

There will be such an error when installing the on-demand loading of element UI under the official documentation of Vue.

Error:Plugin/Preset files are not allowed to export objects, only functions

In the official document of element

On demand import

With the help of   Babel plugin component, we can only introduce the required components to reduce the project volume.

First, install the Babel plugin component:

npm install babel-plugin-component -D

Then, change. Babelrc to:

{
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

At this time, after the installation and configuration are completed according to the official documents, an error will be reported when NPM run serve is started

Error: Cannot find module 'babel-preset-es2015'

This is due to the lack of Babel preset es2015 dependency

Just install the Babel preset es2015 dependency

npm i babel-preset-es2015 --save

This is OK, but sometimes you will still report an error when you start after installation

Error: Plugin/Preset files are not allowed to export objects, only functions.

I changed the preset in the babel.config.js file in the project     Not used in the official element UI documentation

Es2015, but change the content of babel.config.js to the following:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
    ["@babel/preset-env", {
      "useBuiltIns": "entry"
    }]
  ],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

Then install the dependencies on the command line

npm install --save-dev @babel/preset-env

This solves the error.

[Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined

An error was found while running the Vue project

Syntax Error: TypeError: Cannot read property 'parseComponent' of undefined

Solution: my version numbers of Vue and Vue template compiler are different.

    1. uninstall Vue template compiler first
npm uninstall vue-template-compiler
      1. reinstall NPM uninstall Vue template compiler. The version number is the same as Vue
 npm install [email protected]

Finally, run NPM run serve again

Duplicate keys detected: ‘***‘. This may cause an update error

Encountered while developing Vue project    Duplicate keys detected: ’13’. This may cause an update error. This error will not affect the page display, but will always be printed on the console. As shown in the figure  

 

Error reason: the key value set during V-for loop is not unique. As shown in the figure  

Solution

The key that sets the V-for loop is unique. As shown in the figure  

 

 

   

 

error Expected an assignment or function call and instead saw an expression

error Expected an assignment or function call and instead saw an expression

Why does recursion always report errors and cannot run?

 

Now there are two ways to deal with it

1. Add a return before the expression

res.data.forEach(item =>
          item.attr_vals.length === 0 ?[] : item.attr_vals.split(' ')
        )

2. Remove curly braces  

 res.data.forEach(item => {
          returnitem.attr_vals.length === 0 ?[] : item.attr_vals.split(' ')
            }
        )

 

Error in v-on handler (Promise/async): “Error: Request failed with status code 500“

Error in v-on handler (promise/async): “error: request failed with status code 500”
click OK to add data. The post request
reports an error:

It is found that the post request needs to pass parameters. The parameter of the object format is passed. If this parameter is added in the figure below, the request is successful

[Solved] Vue Error: Failed to mount component: template or render function not defined

Vue2 fails to mount component: template or render function not defined

There are probably the following situations. Simply record…

1. When a page references a component

Let’s take a look at the current directory structure

The directory structure of the current page is viptag/index.vue main page; The components composed of tagroute.js, tagroute.scss and tagroute.vue under component are split because the current component logic and style part are relatively long; At this time, let’s go back to the main page of viptag/index.vue and have a look at import

import   tagRule   from  “./ components/tagRule”; In this case, the specific imported file cannot be recognized, resulting in an error message, which is changed to import   tagRule   from  “./ components/tagRule.vue”; Just

2. When the router/index.js route references the page

Error example

As shown in the figure above, component:   The current writing method of require (‘@/views/viptag/index. Vue’) causes an error

The reason is that: require is the module import method of commonjs, and the export default written during component definition is ES6. Therefore, the result of require import is actually an object with default attribute, so components in Vue will report an error when using this, and it happens that components are used for the registration of named view components in Vue, The reasonable usage should be require (‘xxx. Vue ‘). Default or import

Solve the asynchronous execution of callback function in Axios request processing interceptor

The Axios request handles the asynchronous execution of the callback function in the interceptor, resulting in the failure to get the token refresh

https.interceptors.request.use(config => {
    if (Determine if the token is expired) {
        let promisefresh = new Promise(function (resolve, reject) {
            WebViewJavascriptBridge.callHandler(
                "getUserInfo",
                {
                    key: "111"
                },
                function (responseData) {
                    removeItem("FToken");
                    setItem("FToken", responseData);
                    config.headers["FToken"] = getItem("FToken"); 
                    config.headers["FAppType"] = "M"; 
                    resolve(config);
                }
            );
        });
        return promisefresh;
    } else {
        config.headers["FToken"] = getItem("FToken"); 
        config.headers["FAppType"] = "M"; 
        return config;
    }
}, function (error) {
    return Promise.reject(error);
});

axios.interceptors.response.use();

Vue3 uses element plus package to solve the problem of occasionally disordered code on the icon after it goes online

Unlike element UI, element plus does not use node sass or dart sass, but sass and sass loader. At first, I thought it might be that the sass version and sass loader version of the project are inconsistent with the version of element plus, so I deleted the version of my project and installed the version consistent with the version used by element plus, but the problem is not solved. The version is as follows:

 "devDependencies": {
    "postcss-loader": "^5.3.0",
    "sass": "^1.35.1",
    "sass-loader": "^10.0.1",
  }

After tossing around for a while, I found an article on the Internet (the solution of icon garbled code packaged by dart sass compiled element UI). This is a solution for element UI, but I don’t know whether it is effective for element plus. Therefore, after using this method for element plus according to the instructions, I found that it is also effective, so I made a record, The steps are as follows:
1. Install the plug-in CSS Unicode loader;

yarn add css-unicode-loader -D //npm install css-unicode-loader -D

2. In vue.config.js configuration, I used the object writing method, and here it is modified to function writing method

// vue.config.js
module.exports = {
  configureWebpack: config => {
    config.module.rules.filter(rule => {
      return rule.test.toString().indexOf("scss") !== -1;
    }).forEach(rule => {
        rule.oneOf.forEach(oneOfRule => {
          oneOfRule.use.splice(oneOfRule.use.indexOf(require.resolve('sass-loader')), 0,
          	{ loader: require.resolve("css-unicode-loader")})
        })
      })
    }
}

Vue modifies the value passed by props error: Avoid mutating a prop directly since the value will be overwritten whenever the par

When doing a project, you will sometimes encounter this kind of error
this sentence means to avoid changing the prop directly, because as long as the parent component is re rendered, the value will be overridden. Instead, use data or calculate properties based on the prop value
you can’t directly change the props passed by the parent component, so what can you do?You can use emit to trigger the events of the parent component
parent component

<template>
    <div class="class">
        <Student :show="isShow" @hideStudent="hideStudent" />
        <button @click="showStudent">点我显示学生</button>
    </div>
</template>

<script>
import Student from "./student";
export default {
    name: "class",
    components: { Student },
    data() {
        return {
            isShow: false,
        };
    },

    methods: {
        showStudent() {
            this.isShow = true;
        },
        hideStudent() {
            this.isShow = false;
        },
    },
};
</script>

Subcomponents

<template>
    <div class="student" v-show="show">
        <nav>Mike</nav>
        <button @click="close">点我关闭student</button>
    </div>
</template>

<script>
export default {
    name: "student",
    props: {
        show: {
            type: Boolean,
            default:false
        },
    },
    methods: {
        close() {
            this.$emit("hideStudent");
        },
    },
};
</script>

Of course, subcomponents can also write like this, using watch to listen

<template>
    <div class="student" v-show="showStudent">
        <nav>Mike</nav>
        <button @click="close">点我关闭student</button>
    </div>
</template>

<script>
export default {
    name: "student",
    props: {
        show: {
            type: Boolean,
            default:false
        },
    },
    data() {
        return {
            showStudent:false
        };
    },
    watch:{
        show(){
            this.showStudent=this.show
        },
    },
    methods: {
        close() {
            this.$emit("hideStudent");
        },
    },
};
</script>

Finally, let’s take a look at the rendering


for more details about the value transmission of vueprops, see the value transmission of Vue parent-child components

When using iView, report: no parsing error parsing error: x-invalid-end-tag solution

When using Iview, it reports: https://google.com/#q=vue%2Fno-parsing-error Parsing error: x-invalid-end-tag Solution
Phenomenon

✘  https://google.com/#q=vue%2Fno-parsing-error  Parsing error: x-invalid-end-tag
  src\pages\TheAdminDashboard.vue:11:25
                          </MenuItem>

Solution:

There are two solutions:
1. Modify MenuItem to: menu item 2

2. Add the following in the root directory. Eslintrc.js file rules:

"vue/no-parsing-error": [2, { "x-invalid-end-tag": false }]