A, watch

Specifying immediate: true in the options argument triggers the callback immediately with the current value of the expression:

var unwatch = vm.$watch(
  'value'.function () {
    doSomething()
    if (unwatch) {
      unwatch()
    }
  },
  { immediate: true})Copy the code

Second, with

Mixins provide a very flexible way to distribute reusable functionality in Vue components.

Common mix:

var mixin = {
  methods: {
    foo: function () {
      console.log('foo')},conflicting: function () {
      console.log('from mixin')}}}var vm = new Vue({
  mixins: [mixin],
  methods: {
    bar: function () {
      console.log('bar')},conflicting: function () {
      console.log('from self')
    }
  }
})

vm.foo() // => "foo"
vm.bar() // => "bar"
vm.conflicting() // => "from self"
Copy the code

Global mixing:

// Inject a handler for the custom option 'myOption'.
Vue.mixin({
  created: function () {
    var myOption = this.$options.myOption
    if (myOption) {
      console.log(myOption)
    }
  }
})

new Vue({
  myOption: 'hello! '
})
// => "hello!"
Copy the code

The exact attribute of the <router-link> tag

The default class name is activated or not based on the inclusion of a match. The default is false. When set to true, it contains matches, and only addresses containing configurations are added to the highlight style class name.

Four, Vue. Use (plugins)

If the plug-in is an object, the install method must be provided.

Use the plug-in with the global method vue.use ().