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

The Vue instance

Looking at ourapp.jsfile, let's now create ourroot instanceof Vue.js by using thenewoperator with theVueobject.

app.js:

var app = new Vue();

When you create a Vue instance, you will usually want to pass in a configuration object as an argument. This object is where your project's custom data and functions are defined.

app.js:

var app = new Vue({
  el: '#app'
});

As our project progresses, we'll be adding much more to this configuration object, but for now we've just added theelproperty that tells Vue where to mount itself in the page.

You can assign to it a string (a CSS selector) or an HTML node object. In our case, we've used the#appstring,which is a CSS selector referring to the element with the appID.

index.html:

<p id="app">
  <!--Mount element-->
</p>

Vue has dominion over the element it mounts on and any child node. For our project so far, Vue could manipulate thepwith theheaderclass, but it could not manipulate thepwith thetoolbarID. Anything placed within this latterp will be invisible to Vue.

index.html:

<body>
<p id="toolbar">...</p>
<p id="app">
  <!--Vue only has dominion here-->
  <p class="header">...</header>
  ...
</p>
<script src="node_modules/vue/dist/vue.js"></script>
<script src="app.js"></script>
</body>

From now on, we'll refer to our mount node and its children as ourtemplate.

主站蜘蛛池模板: 泰顺县| 无棣县| 湘阴县| 房山区| 内黄县| 岫岩| 天长市| 岳池县| 嘉荫县| 山东省| 万载县| 榆林市| 聂拉木县| 电白县| 蒙山县| 鄂尔多斯市| 洛浦县| 普宁市| 嘉荫县| 清远市| 阿瓦提县| 天长市| 溆浦县| 临沂市| 赣州市| 垣曲县| 肥西县| 卢氏县| 阳东县| 旌德县| 同江市| 和静县| 四子王旗| 永春县| 军事| 黔东| 东方市| 淳化县| 吴忠市| 都匀市| 长沙县|