Tag Archives: javascript

NPM installØin sprintf- [email protected] Wealth: not available https://github.com/nhn/raphael.git/ “

npm install –registry= https://registry.npm.taobao.org
Command installation error
stuck in sprintf- [email protected] Checking installable status for a short time, Then an error is reported as follows (the domestic network speed of this link should be slow):
fatal: unable to access‘ https://github.com/nhn/raphael.git/ ’

test according to the online method: search the. Gitconfig file (generally in the user directory of Disk C, such as C: \ users * \ path), Then add the following paragraph:
[url “HTTPS://”]
instead of = git://
then the following error is reported:

it can be seen from the above figure that there are problems in the installation of some other packages because HTTPS is replaced with git, that is, HTTPS and git cannot be used all. In addition, I guess that the above paragraph of code should mean replacing the website, So I changed the above code as follows:
[url]“ https://github.com/nhn/raphael.git/ ”]
insteadOf = git://github.com/nhn/raphael.git/

Then
NPM install — registry= https://registry.npm.taobao.org
Then you can run Vue element admin successfully. The screenshot after success is as follows:

[Solved] VS Code Debug JavaScript Error: “crbug/1173575, non-JS module files deprecated”

  According to the online method (VSCODE debug Javascript), after installing the debugger for Chrome extension, debug JavaScript, the result is not able to display the web page in the browser correctly, the wrong report: “crbug/1173575, non-JS module files deprecated”, as shown in the following figure:

resolvent:

Open launch.json and change the port number in “URL” in “configurations” to the port number of live server

Save, and then press F5 again to debug normally

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();

[Solved] Uncaught SyntaxError: Unexpected token ‘<‘

This error is sometimes reported in front-end deployment, as shown in the following figure:

it is generally caused by improper configuration. Modify the vue.config.js file

// If the application is deployed on a subpath, you will need to specify this subpath with this option. For example, if your application is deployed at https://www.baidu.vip/admin/, set the baseUrl to /admin/.

publicPath: process.env.NODE_ENV === 'production' ?'/' : '/admin/',

[Solved] vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: “TypeError: Cannot read property ‘length‘

When using element UI as the form check box, the error vue.runtime.esm.js appears?2b0e: 619 [Vue warn]: error in render: “typeerror: cannot read property ‘length’, as shown in the following figure:

the code is as follows:

the solution is to add the checklist field in the form object as follows:

export default {
	data() {
 		return {
			form: {
				checkList: []
			}
		}
 	}
}

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

Use of $watch in Vue (solve rangeerror: maximum call stack size exceeded)

Problems encountered:

In a requirement, the change of a form needs a function of history recording. Because the form is very large (it is to edit an article), it is impossible to be specific to a certain attribute, so the method of watch monitoring is adopted, and {deep: true} is set. However, when previewing, I encountered the error of rangeerror: maximum call stack size exceeded . After some investigation, I found that it was caused by watch monitoring, and then I didn’t know what the problem was.

Even if nothing is written in the business code, a simple console.log will not work. As long as deep: true is set, an error will be reported, which is a headache. I didn’t find a similar case on the Internet. I thought again: since the error lies in the watch, can I dynamically monitor and cancel monitoring ?I found the answer on the official website https://cn.vuejs.org/v2/api/#vm -watch

Basic use of $watch (refer to the official website)

VM. $watch (exporfn, callback, [options]) the return value is a {function} unwatch , which returns a function to cancel the observation, which is used to stop the trigger callback option: deep, deep listening option: immediate, whether to execute once immediately

// Key Path
vm.$watch('a.b.c', function (newVal, oldVal) {
  // Do something
})

// function
var unwatch = vm.$watch(
  function () {
    // The expression `this.a + this.b` is called every time a different result is reached
    // the handler function will be called.
    // This is like listening for an undefined computed property
    return this.a + this.b
  },
  function (newVal, oldVal) {
    // Do something
  }
)

// Cancel the listener

unwatch()

My solution, for reference

// Call setWatchChapters when created, call removeWatchChapters in other cases, depending on the business case
export default {
	...
	data () {
		return {
			unWatchChapters: null
		}
	},
	created(){
		this.setWatchChapters()
	},
	methods:{
		setWatchChapters () { // Setting up a listener for chapters
			if (!this.unWatchChapters) { // prevent setting listeners more than once
				setTimeout(() => { // There are still some bugs, so use setTimeout to add to the event queue
					this.unWatchChapters = this.$watch('report.chapters', () => {
						// do something
					}, { deep: true })
				}, 0)
			}
    	},
    	removeWatchChapters () { // Unlisten to chapters
			if (this.unWatchChapters) {
				this.unWatchChapters()
				this.unWatchChapters = null
			}
		}
	}
}

Method of getting app. Config. Globalproperties. X directly from vue3

Suppose we define a global method in main. JS

//main.js

 app.config.globalProperties.$hello = name => {
      console.log('hello ' + name)
 }

Call this method in other pages.

//other.js

import { getCurrentInstance } from "vue";
const { appContext } = getCurrentInstance();

const callHello = ()=>{
 appContext.config.globalProperties.$hello('jay');
}

callHello()
//'hello jay'