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

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.

主站蜘蛛池模板: 万山特区| 波密县| 察隅县| 铜鼓县| 东源县| 凤山市| 新巴尔虎右旗| 哈密市| 凤台县| 洛扎县| 紫阳县| 耿马| 泽普县| 滦平县| 观塘区| 乐陵市| 莱芜市| 乌鲁木齐市| 岱山县| 莲花县| 开化县| 大悟县| 潞西市| 巩义市| 梨树县| 湘潭市| 自贡市| 冀州市| 治县。| 锦屏县| 尤溪县| 泰和县| 云浮市| 乐都县| 东乡县| 泰宁县| 田阳县| 红原县| 皋兰县| 娄烦县| 内江市|