首页 > 其他分享 >Vue生命周期钩子函数

Vue生命周期钩子函数

时间:2023-05-19 15:32:50浏览次数:39  
标签:el 生命周期 console log 钩子 filter Vue data


  1. 每个Vue实例创建时,都会经历一系列的初始化过程,同时也会调用相应的生命周期钩子,我们利用这些钩子,可以在合适的时机执行我们的业务逻辑。
  2. vue生命周期共分为四个阶段,八个基本钩子函数
<script>
export default {
  data() {
    return {
      filter: "all",
    };
  },
  beforeCreate() {
    console.log("==============" + "beforeCreated" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  },
  created() {
    console.log("==============" + "created" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  },
  beforeMount() {
    console.log("==============" + "beforeMount" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  },
  mounted() {
    console.log("==============" + "mounted" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  },
  beforeUpdate() {
    console.log("==============" + "beforeUpdate" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  },
  updated() {
    console.log("==============" + "updated" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  },
  beforeDestroy() {
    console.log("==============" + "beforeDestroy" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  },
  destroyed() {
    console.log("==============" + "destroyed" + "===================");
    console.log(this.$el);
    console.log(this.$data);
    console.log(this.filter);
  }
};
</script>

Vue生命周期钩子函数_vue


3. vue生命周期图

Vue生命周期钩子函数_初始化_02


标签:el,生命周期,console,log,钩子,filter,Vue,data
From: https://blog.51cto.com/u_16120408/6312766

相关文章

  • less在vue项目中的全局变量设置
    1,使用全局变量的目的:sass或者less都提供变量设置,在需求切换主题的项目中使用less或者sass变量,只要修改变量值,编译后所有用到该变量的样式都会被修改为你想要的效果2,安装sass-resources-loadernpminstallsass-resources-loader--save-dev3,找到build文件夹下面的utils.jsreturn{......
  • Vue.js学习记录之在元素与template中使用v-if指令实例(转贴)
    语法比较简单,直接上代码:<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <title></title> <scriptsrc="https://cdn.bootcss.com/vue/2.2.2/vue.......
  • Vue路由router
    1、总体结构2、路由说明 ......
  • vue component:is 组件切换
    <template><Child1/><Child2/><component:is="currentComp"></component><el-button@click="compChange">切换组件</el-button></template><scriptsetup>import{shallo......
  • spring bean的生命周期
    1.SpringBean的生命周期简介Springbean的生命周期是指Bean在Spring(IoC)中从创建到销毁的整个过程。在Spring框架中,Bean的生命周期包括以下阶段:实例化:通过构造函数或工厂方法创建Bean实例。属性赋值:调用Bean实例的setter方法将属性值注入到Bean中。初始化:执行Bean实例......
  • 【小小demo】Springboot + Vue 增删改查
    vue-table-ui该工程提供的是一个简单的Vue+Element-UI的表格,增删改查操作。工程代码在最下面。环境jdk1.8ideamavenspringboot2.1.1.RELEASE示例首页查询新增修改删除官方文档Element-Ui:https://element.eleme.cn/#/zh-CN/component/installationV......
  • 在 Vue 中使用 iframe 嵌套页面
    1.在Vue中引入iframe在Vue中使用iframe技术需要在组件中引入iframe标签,代码如下:<template><div><iframesrc="https://www.baidu.com"></iframe></div></template>2.设置iframe的样式在Vue中使用iframe技术需要设置iframe的样式,包括宽度、......
  • Vue 自定义指令实践
    Vue自定义指令一个自定义指令由一个包含类似组件生命周期钩子的对象来定义。钩子函数会接收到指令所绑定元素作为其参数。在 <scriptsetup> 中,任何以 v 开头的驼峰式命名的变量都可以被用作一个自定义指令。eg: 在上面的例子中,vFocus 即可以在模板中以 v-focus 的形......
  • Vue Ant Design Pro 中定制主题
    VueAntDesignPro中定制主题需求定制主题去除“正在切换主题”过渡效果 需求项目要求使用草绿色的主题色并且去除如下的loading效果定制主题这里可以参照AntDesignProofVue官方文档哦定制方式是使用 less 的modifyVars的方式进行覆盖变量官方文档......
  • 在Vue2项目中遇到的问题汇总
    1问题1:Proxyerror:Couldnotproxyrequest/studentsfromlocalhost:8080tohttp://localhost:5000/.SeehtProxyerror:Couldnotproxyrequest/studentsfromlocalhost:8080tohttp://localhost:5000/.Seeht终端报错:浏览器报错这个里面给的文件没有打开,打......