【问题标题】:How to trigger an event inside the Created method?如何在 Created 方法中触发事件?
【发布时间】:2018-12-15 02:35:44
【问题描述】:

我想获取 GET 参数的值并触发一个事件。如何在 Created 方法中触发事件?

我试过这种方式,但是没有找到点击方式:

created(){
    if(this.$route.query.text!=''){
        this.textToTranslate = this.$route.query.text;
        const elem = this.$refs.languageSelect;
        elem.change();
    }
  },

【问题讨论】:

  • 尝试使用mounted 而不是created
  • 引用直到 mounted 才可用,因为它们是对创建的 DOM 元素的引用。

标签: vue.js vuejs2


【解决方案1】:

使用 mounted,因为您正在与 DOM 元素交互,这些元素在 created 生命周期挂钩中将不可用。欲了解更多信息:another question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-12
    • 2011-03-16
    • 2023-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 2020-12-06
    相关资源
    最近更新 更多