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

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.

主站蜘蛛池模板: 南皮县| 淮北市| 民县| 清水县| 类乌齐县| 安宁市| 宁阳县| 庆安县| 桓仁| 登封市| 兴安盟| 阿拉尔市| 奉节县| 竹山县| 维西| 信宜市| 祁连县| 光泽县| 大方县| 通辽市| 汉川市| 罗定市| 桑植县| 甘孜| 汉中市| 故城县| 广饶县| 天柱县| 昭平县| 乐至县| 贡嘎县| 谢通门县| 中方县| 宁陵县| 江阴市| 正镶白旗| 达日县| 红安县| 承德县| 尉氏县| 栖霞市|