案例:Vue.js案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>Vue 测试实例 - W3xue教程(w3xue.com)</title>
6
<script src="//unpkg.com/vue/dist/vue.js"></script>
7
</head>
8
<body>
9
<div id="app">
10
    <p>页面载入时,input 元素自动获取焦点:</p>
11
    <input v-focus>
12
</div>
13
14
<script>
15
// 注册一个全局自定义指令 v-focus
16
Vue.directive('focus', {
17
  // 当绑定元素插入到 DOM 中。
18
  inserted: function (el) {
19
    // 聚焦元素
20
    el.focus()
21
  }
22
})
23
// 创建根实例
24
new Vue({
25
  el: '#app'
26
})
27
</script>
28
</body>
29
</html>