案例: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
// 创建根实例
16
new Vue({
17
  el: '#app',
18
  directives: {
19
    // 注册一个局部的自定义指令 v-focus
20
    focus: {
21
      // 指令的定义
22
      inserted: function (el) {
23
        // 聚焦元素
24
        el.focus()
25
      }
26
    }
27
  }
28
})
29
</script>
30
</body>
31
</html>