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

  • 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.

主站蜘蛛池模板: 新乡县| 新竹市| 西城区| 社旗县| 临清市| 沁水县| 乌鲁木齐县| 寻乌县| 阳城县| 崇阳县| 龙井市| 伊宁市| 德江县| 高碑店市| 临清市| 峡江县| 乌海市| 博爱县| 西林县| 怀集县| 宜阳县| 万安县| 来凤县| 南乐县| 鹰潭市| 突泉县| 彰化市| 马山县| 浙江省| 股票| 个旧市| 巴青县| 政和县| 呈贡县| 微博| 乐亭县| 青岛市| 达拉特旗| 曲阜市| 寿光市| 昌江|