标签:实例 使用 com tee 操作 str bar log http
正文




new Vue({
  el: ‘#app‘,
  beforeCreate: function () {
    console.log(‘调用了beforeCreat钩子函数‘)
  },
  created: function () {
    console.log(‘调用了created钩子函数‘)
  },
  beforeMount: function () {
    console.log(‘调用了beforeMount钩子函数‘)
  },
  mounted: function () {
    console.log(‘调用了mounted钩子函数‘)
  }
})

new Vue({
  beforeCreate: function () {
    console.log(‘调用了beforeCreat钩子函数‘)
  },
  created: function () {
    console.log(‘调用了created钩子函数‘)
  },
  beforeMount: function () {
    console.log(‘调用了beforeMount钩子函数‘)
  },
  mounted: function () {
    console.log(‘调用了mounted钩子函数‘)
  }
})

var vm = new Vue({
  beforeCreate: function () {
    console.log(‘调用了beforeCreat钩子函数‘)
  },
  created: function () {
    console.log(‘调用了created钩子函数‘)
  },
  beforeMount: function () {
    console.log(‘调用了beforeMount钩子函数‘)
  },
  mounted: function () {
    console.log(‘调用了mounted钩子函数‘)
  }
})
vm.$mount(‘#app‘)


new Vue({
  el: ‘#app‘,
  template: ‘<div id="app"><p>模板在templated参数中找到了哟~</p></div>‘
})
demo:

<div id="app"><p>模板是在外部HTML中找到的~</p></div>
创建对象实例:
new Vue({
  el: ‘#app‘
})

<div id="app"><p>模板是在外部HTML中找到的~</p></div>
new Vue({
  el: ‘#app‘,
  template: ‘<div id="app"><p>模板在templated参数中找到了哟~</p></div>‘
})

new Vue({
  el: ‘#demo‘,
  render (createElement) {
    return (....)
  }
})
<div>
  <header>
    <h1>I‘m a template!</h1>
  </header>
  <p v-if="message">
    {{ message }}
  </p>
  <p v-else>
    No message.
  </p>
</div>
function anonymous() {
  with(this){return _c(‘div‘,[_m(0),(message)?_c(‘p‘,[_v(_s(message))]):_c(‘p‘,[_v("No message.")])])}
}
 
对于这一点,我也感到有些迷惑,百度后之后也没什么头绪,最后我思考的结果是这样的:正因为render函数和template选项的“优先级”比外部HTML要高,所以,最后一般会存在一个外部HTML模板被Vue实例本身配置的模板所“替代”的过程也就是上图所说的 “replace”

var vm = new Vue({
  el: ‘#app‘,
  data: {
    number: 1
  },
  template: ‘<div id="app"><p></p></div>‘,
  beforeUpdate: function () {
    console.log(‘调用了beforeUpdate钩子函数‘)
  },
  updated: function () {
    console.log(‘调用了updated钩子函数‘)
  }
})
 
vm.number = 2

var vm = new Vue({
  el: ‘#app‘,
  data: {
    number: 1
  },
  // 在模板中使用number这个数据
  template: ‘<div id="app"><p>  {{ number }} </p></div>‘,
  beforeUpdate: function () {
    console.log(‘调用了beforeUpdate钩子函数‘)
  },
  updated: function () {
    console.log(‘调用了updated钩子函数‘)
  }
})
 
vm.number = 2
 



.
标签:实例 使用 com tee 操作 str bar log http
原文地址:https://www.cnblogs.com/jianxian/p/11993762.html