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

  • Vue.js Quick Start Guide
  • Ajdin Imsirovic
  • 163字
  • 2021-06-24 18:23:54

Using Vue's data option as a function

Note that the data option of our Vue instance can be either an object or a function. An example of data as an object can be seen in the previous code. Using data as a function is easy as well.

Data as an object doesn't work well with reusable components. For this reason, using data as a function is, generally speaking, a more useful way to use the data option in Vue.

Let's see another pen. This time, we'll use the data option as a function, instead of as an object. The pen is available here: https://codepen.io/AjdinImsirovic/pen/aKVJgd. The only change we'll make is in our Vue code:

new Vue({
el: '#entryPoint',
data() {
return {
heading1: 'Just an h1 heading here',
heading2: 'heading 2 here',
paragraph1: 'Vue JS data as a function'
}
}
})

Now that we're familiar with the very basics of Vue syntax, let's look at what it can be used for.

主站蜘蛛池模板: 多伦县| 庄浪县| 阜阳市| 胶州市| 海伦市| 泸西县| 建阳市| 房产| 临泽县| 辉县市| 乌恰县| 扶沟县| 昌平区| 江西省| 乌苏市| 湖口县| 仲巴县| 哈尔滨市| 贵德县| 宜兴市| 孟津县| 丘北县| 大宁县| 武城县| 禄劝| 公主岭市| 临沭县| 沈丘县| 康马县| 高陵县| 松潘县| 石河子市| 中西区| 河东区| 景东| 怀柔区| 仁怀市| 双流县| 临桂县| 留坝县| 岱山县|