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

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)
  },
},
主站蜘蛛池模板: 开封县| 鄯善县| 卢湾区| 司法| 伊宁县| 托里县| 双峰县| 平湖市| 兰考县| 长乐市| 定襄县| 疏附县| 岳阳市| 东丽区| 霍城县| 江孜县| 通渭县| 江永县| 确山县| 新民市| 星座| 恩平市| 定远县| 四平市| 宝鸡市| 房山区| 绍兴县| 德化县| 兴山县| 乌拉特后旗| 昭通市| 泰来县| 拜泉县| 杭州市| 颍上县| 台湾省| 凯里市| 丹凤县| 宜君县| 四会市| 普宁市|