Tag Archives: vue

Vue calculates attributes and passes parameters to the computed method

Vue computes attribute computed that no direct arguments can be passed
You can use closure functions to implement the need to pass parameters

<template>
  <span>{{fmtWeight(1)}}</span>
</template>

<script>
export default {
  data() {
    return {
      weight: 100
    };
  },
  computed: {
    fmtWeight() {
      return num => {
        return this.weight.toFixed(num)
      }
    }
  }
};
</script>

Command failed: NPM install — loglevel error — registry= https://registry.npm.taobao.org

Use the vue – cli create project has the following error: the command failed: NPM install – loglevel error – registry=https://registry.npm.taobao.org – disturl=https://npm.taobao.org/dist

the solution has the following kinds:
Make sure that the vue-cli, NPM, node, Versions had better high node must be
1. 8 + NPM install chromedriver – chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver
finished to recreate the project (this approach is not once and for all)
2. NPM cache clean — force Clear the NPM cache (if it doesn’t work, it’s not a cache problem)
3. If the above two steps or not To install the following taobao source
NPM install – g CNPM – registry=https://registry.npm.taobao.org
4. Find your computer C: \ Users \ Administrator found. vuerc the file
initial is true instead of false can

How to Fix “the data of store is lost after Vue refreshes the page”

When the page is refreshed, the VUE instance is reloaded, and the store will be reset. The store can be stored in the local localStorage, sessionStorage and cookie before the definition is refreshed. The localStorage is permanent storage, and the page data that was opened last time will be read when the page is reopened. According to my needs, the most appropriate is sessionStorage.
before upload fires when the page is refreshed. You can listen to this method to store the page to sessionStorage before the page is refreshed. Even when page refresh
of course, read the sessionStorage data into the store, read and stored, are written in the app. Vue.

export default {
  name: 'app',
  created () {
    // Read sessionStorage on page load
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))))
    }
    // Save the store to sessionStorage when the page is refreshed
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    })
  }
}

Vue uses Axios

Step 1: Install Axios

$ npm install axios

Step 2: Import Axios in main.js

import VueAxios from 'vue-axios';
import axios from 'axios';
Vue.prototype.$axios = axios;

Step 3: Write the Axios request code

created(){
    const  _this = this
    this.$axios.get('http://localhost:8081/book/findall').then(function (resp) {
        _this.books = resp.data;
      })

Vue error resolution: typeerror: cannot read property ‘_ t’ of undefined”

[Vue warn]: Error in render: “TypeError: Cannot read property ‘_t’ of undefined”
The compatibility issue between Vue and i18n is the multi-language configuration used in the project. The solution is as follows:

    Vue.use(iView) 

replace

Vue.use(iView, {
  i18n: function(path, options) {
    let value = i18n.t(path, options)
    if (value !== null && value !== undefined) {
      return value
    }
    return ''
  }
})

Internationalization other items are configured unchanged and are recorded only.
Reference articles:
https://github.com/iview/iview/issues/1090

Solution to the problem of selecting node sass when creating vue-cli3

Because :
vue-cli3.0 defaults to using the yarn package management tool instead of the original NPM

In yarn, node-sass, the default download will most likely fail if you don’t over the wall

The solution

	yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g

So when use the yarn to download the node – sass don’t stuck an error failed to install
this method not only solve the vue cli3 installation node – sass error
is used to solve the yarn package management tools installation node – sass error problem
Problem solving

JS error: unexpected token u in JSON at position 0

At first glance, this error is confusing, but it is simply due to json.parse parsing of undefined.

JSON.parse is used somewhere, but the argument passed in is not a qualified JSON string.
Parse parse parse parse parse parse parse parse parse parse
Parse before you judge
 


Come from:
https://www.cnblogs.com/yangxunwu1992/p/8964780.html

Cnpm: unable to load file

System search for PowerShell, right-click PowerShell to run as an administrator, and then enter the following command to execute,

set-ExecutionPolicy RemoteSigned

Then, select Y to complete the setup