- Vue.js 2 Web Development Projects
- Guillaume Chau
- 167字
- 2021-07-02 22:34:25
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) }, },
推薦閱讀
- Arduino by Example
- Unity 2020 Mobile Game Development
- Selenium Design Patterns and Best Practices
- Learning Raspbian
- Keras深度學(xué)習(xí)實戰(zhàn)
- Windows內(nèi)核編程
- 深入淺出React和Redux
- Python全棧數(shù)據(jù)工程師養(yǎng)成攻略(視頻講解版)
- Learning YARN
- INSTANT Yii 1.1 Application Development Starter
- Building Serverless Architectures
- RESTful Web Clients:基于超媒體的可復(fù)用客戶端
- INSTANT JQuery Flot Visual Data Analysis
- 3D Printing Designs:Octopus Pencil Holder
- React and React Native