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

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)
  },
},
主站蜘蛛池模板: 沙田区| 丹棱县| 房山区| 黑河市| 屯留县| 南岸区| 融水| 通河县| 灵台县| 武平县| 井研县| 岢岚县| 扎鲁特旗| 黎川县| 济南市| 绿春县| 德保县| 云阳县| 旬邑县| 平利县| 兴海县| 秦安县| 靖安县| 沁阳市| 固镇县| 行唐县| 林西县| 体育| 马边| 泸西县| 沾化县| 彭泽县| 河北省| 象州县| 望奎县| 井研县| 荣成市| 枞阳县| 元朗区| 商水县| 柏乡县|