/* Vue实例化对象创建之前 */
- "app">
- <h1>{{msg}}h1>
-
- <script src="./vue.min.js">script>
- <script>
- new Vue({
- el: "#app",
- data: {
- msg: "前端工作"
- },
- // 最先执行的函数
- beforeCreate: function () {
- console.log("vue实例化对象创建之前");
- // console.log(this.msg);
- },
- created() {
- console.log("vue实例化对象创建之后");
- console.log(this.msg);
- console.log(document.querySelector("#app"));
- // created 在生命周期里面不可能获取节点
- console.log(this.$el);
- // ⭐一般用来获取接口数据,速度更快,因为这个时候已经获取到data的数据了
- setTimeout(() => {
- this.msg = "从接口获取的数据"
- }, 100)
- },
- beforeMount() {
- // beforeMount 在生命周期里面可获取节点,但是不能显示出data数据
- console.log('beforeMount', this.$el);
- },
- mounted() {
- // ⭐操作元素节点的时候,写在mounted
- console.log('mounted', this.$el);
- }
-
- })
- script>
- beforeMount() {
- // beforeMount 在生命周期里面可获取节点,但是不能显示出data数据
- console.log('beforeMount', this.$el);
- },
- mounted() {
- // 操作元素节点的时候,写在mounted
- console.log('mounted', this.$el);
- this.id = setInterval(() => {
- this.num++;
- console.log(this.num);
- }, 1000)
- },
- // 在data更新之前执行
- beforeUpdate() {
- console.log('beforeUpdate', this.msg, this.$el);
- },
- updated() {
- console.log('beforeUpdate', this.msg, this.$el);
- },
- beforeDestroy() {
- clearInterval(this.id)
- console.log('beforeDistory', this.msg, this.$el);
- },
- destroyed() {
- // clearInterval(this.id)
- console.log('destory', this.msg, this.$el);
- },
- methods: {
- changeFn() {
- this.msg = "111111111111111111"
- },
- destroyFn() {
- this.$destroy()
- }
- }