首页 > 代码库 > Vuejs学习笔记1

Vuejs学习笔记1

首次写vue可能会出现:[Vue warn]: Cannot find element: #app

这是因为你的js在html页面头部引入的原因,自定义js文件要最后引入,因为要先有元素id,vue才能获取相应的元素。

示例:

1.index.js

var app = new Vue({
  el : ‘#app‘,
  data: {
    message: ‘Hello Vue.js!‘
  }
})

2.index.html

<html>
<head>
  <title>Vuejs</title>
</head>
<body>
  <div id="app">
    {{ message }}
  </div>
<script src="http://www.mamicode.com/vue.js"></script>
<script src="http://www.mamicode.com/index.js"></script>:这里自定js文件要在最后引入。
</body>
</html>

Vuejs学习笔记1