实例 Vue 使用 created 生命周期挂钩来更改 'text' 数据属性

x
 
<template>
  <h1>Lifecycle Hook 'created' Example</h1>
  <p>Using the created lifecycle hook to change the 'text' data property.</p>
  <p>This is the earliest point in the component's lifecycle where we can access the Vue instance properties.</p>
  <p>text: <pre>'{{ text }}'</pre></p>
</template>
<script>
export default {
  data() {
    return {
      text: 'initial text'
    }
  },
  created(){
    this.text = 'The component is now created';
  }
}
</script>
<style>
pre {
  display: inline;
  background-color: lightgreen;
}
</style>                  

输出结果