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

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)
  },
},
主站蜘蛛池模板: 宝清县| 萨迦县| 招远市| 南部县| 咸宁市| 桃园市| 清丰县| 勃利县| 莒南县| 涞水县| 宜都市| 北辰区| 平度市| 舒兰市| 安陆市| 仪陇县| 青龙| 伊春市| 蓬莱市| 寻乌县| 禄丰县| 白朗县| 丘北县| 栖霞市| 公安县| 滕州市| 南平市| 增城市| 莱芜市| 襄垣县| 含山县| 濉溪县| 林西县| 包头市| 洛南县| 隆安县| 惠州市| 乐平市| 通城县| 汾阳市| 仁寿县|