Vue.js:是否有办法知道何时安装组件实例?

时间:2019-03-09 17:09:07

标签: vue.js vuejs2

每个组件实例中是否可以访问一个布尔值,以了解何时安装组件?

类似的东西:

<template>
  <div>
    <span v-if="$mounted">I am mounted</span>
    <span v-if="$created">I am created</span>
    <span>Called before created and mounted</span>
  </div>
</template>

2 个答案:

答案 0 :(得分:1)

library(rvest)
library(dplyr)

url <- "https://finance.yahoo.com/quote/AAPL/history?p=AAPL"
pgsession <- html_session(url)
pgform <-html_form(pgsession)[[1]]
filled_form <-set_values(pgform,
            "Time Period" =  "5Y",           
            "historicalFilter-selected" = "Historical Prices",
            "historicalFrequency-selected"  = "Monthly"
 )

d <- submit_form(session=pgsession,form=filled_form, POST=url)

y <- d %>%
    html_nodes("table") %>%
    .[[2]] %>%
    html_table(header=TRUE)

和脚本:

Error: Unknown field names: Time Period, historicalFilter-selected, historicalFrequency-selected.

答案 1 :(得分:0)

是的,使用生命周期挂钩。

new Vue({
  data: {
    a: 1
  },
  created: function () {
    // `this` points to the vm instance
    console.log('a is: ' + this.a)
  },
mounted: function () {
console.log("i am mounted in dom");
}
})