Vue Options / Data

时间:2021-01-06 22:19:36   收藏:0   阅读:37

Options / Data

data

var data = { a: 1 }

// direct instance creation
var vm = new Vue({
  data: data
})
vm.a // => 1
vm.$data === data // => true

// must use function when in Vue.extend()
var Component = Vue.extend({
  data: function () {
    return { a: 1 }
  }
})

 

props

// simple syntax
Vue.component(‘props-demo-simple‘, {
  props: [‘size‘, ‘myMessage‘]
})

// object syntax with validation
Vue.component(‘props-demo-advanced‘, {
  props: {
    // type check
    height: Number,
    // type check plus other validations
    age: {
      type: Number,
      default: 0,
      required: true,
      validator: function (value) {
        return value >= 0
      }
    }
  }
})

 

原文:https://www.cnblogs.com/chucklu/p/14241974.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!