官术网_书友最值得收藏!

Computed property

A very powerful feature of Vue is the computed property. It allows us to define new properties that combine any amount of properties and use transformations, such as converting a markdown string into HTML--that's why its value is defined by a function. A computed property has the following features:

  • The value is cached so that the function doesn't rerun if it's not necessary, preventing useless computation
  • It is automatically updated as needed when a property used inside the function has changed
  • A computed property can be used exactly like any property (and you can use computed properties inside other computed properties)
  • It is not computed until it is really used somewhere in the app

This will help us automatically convert the note markdown into valid HTML, so we can display a preview in real time. We just need to declare our computed property in the computed option:

// Computed properties
computed: {
  notePreview () {
    // Markdown rendered to HTML
    return marked(this.content)
  },
},
主站蜘蛛池模板: 瓮安县| 汉阴县| 犍为县| 女性| 东乡族自治县| 赣榆县| 新巴尔虎左旗| 上栗县| 偏关县| 岳池县| 延川县| 垦利县| 威信县| 龙门县| 高邑县| 桐乡市| 易门县| 连江县| 靖州| 慈溪市| 个旧市| 华池县| 嘉定区| 安仁县| 神木县| 柘城县| 左贡县| 林芝县| 亚东县| 沧州市| 合作市| 西昌市| 新丰县| 冕宁县| 怀集县| 通许县| 株洲市| 林州市| 平遥县| 潞西市| 保亭|