vue:Vue.js——60分钟快速入门

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box
  14. }
  15.  
  16. html {
  17. font-size: 12px;
  18. font-family: Ubuntu, simHei, sans-serif;
  19. font-weight: 400
  20. }
  21.  
  22. body {
  23. font-size: 1rem
  24. }
  25.  
  26. table, td, th {
  27. border-collapse: collapse;
  28. border-spacing: 0
  29. }
  30.  
  31. table {
  32. width: 100%
  33. }
  34.  
  35. td, th {
  36. border: 1px solid #bcbcbc;
  37. padding: 5px 10px
  38. }
  39.  
  40. th {
  41. background: #42b983;
  42. font-size: 1.2rem;
  43. font-weight: 400;
  44. color: #fff;
  45. cursor: pointer
  46. }
  47.  
  48. tr:nth-of-type(odd) {
  49. background: #fff
  50. }
  51.  
  52. tr:nth-of-type(even) {
  53. background: #eee
  54. }
  55.  
  56. fieldset {
  57. border: 1px solid #BCBCBC;
  58. padding: 15px;
  59. }
  60.  
  61. input {
  62. outline: none
  63. }
  64.  
  65. input[type=text] {
  66. border: 1px solid #ccc;
  67. padding: .5rem .3rem;
  68. }
  69.  
  70. input[type=text]:focus {
  71. border-color: #42b983;
  72. }
  73.  
  74. button {
  75. outline: none;
  76. padding: 5px 8px;
  77. color: #fff;
  78. border: 1px solid #BCBCBC;
  79. border-radius: 3px;
  80. background-color: #009A61;
  81. cursor: pointer;
  82. }
  83.  
  84. button:hover {
  85. opacity: 0.8;
  86. }
  87.  
  88. #app {
  89. margin: 0 auto;
  90. max-width: 640px
  91. }
  92.  
  93. .form-group {
  94. margin: 10px;
  95. }
  96.  
  97. .form-group > label {
  98. display: inline-block;
  99. width: 10rem;
  100. text-align: right;
  101. }
  102.  
  103. .form-group > input, .form-group > select {
  104. display: inline-block;
  105. height: 2.5rem;
  106. line-height: 2.5rem;
  107. }
  108.  
  109. .text-center {
  110. text-align: center;
  111. }
  112.  
  113. .pagination {
  114. display: inline-block;
  115. padding-left: 0;
  116. margin: 21px 0;
  117. border-radius: 3px;
  118. }
  119.  
  120. .pagination > li {
  121. display: inline;
  122. }
  123.  
  124. .pagination > li > a {
  125. position: relative;
  126. float: left;
  127. padding: 6px 12px;
  128. line-height: 1.5;
  129. text-decoration: none;
  130. color: #009a61;
  131. background-color: #fff;
  132. border: 1px solid #ddd;
  133. margin-left: -1px;
  134. list-style: none;
  135. }
  136.  
  137. .pagination > li > a:hover {
  138. background-color: #eee;
  139. }
  140.  
  141. .pagination .active {
  142. color: #fff;
  143. background-color: #009a61;
  144. border-left: none;
  145. border-right: none;
  146. }
  147.  
  148. .pagination .active:hover {
  149. background: #009a61;
  150. cursor: default;
  151. }
  152.  
  153. .pagination > li:first-child > a .p {
  154. border-bottom-left-radius: 3px;
  155. border-top-left-radius: 3px;
  156. }
  157.  
  158. .pagination > li:last-child > a {
  159. border-bottom-right-radius: 3px;
  160. border-top-right-radius: 3px;
  161. }
  162. </style>
  163. </head>
  164. <body>
  165. <!--这是我们的View-->
  166. <div id="app">
  167. <p>{{ message }}</p>
  168. <input type="text" v-model="message" title="">
  169. <h3>Hello, Vue.js!</h3>
  170. <h3 v-if="yes">Yes!</h3>
  171. <h3 v-if="no">No!</h3>
  172. <h3 v-if="name.indexOf('jack') >= 0">Name: {{ name }}</h3>
  173. <!-- v-if 是条件渲染指令,它根据表达式的真假来删除和插入元素 -->
  174. <h1 v-if="age >= 30">Age: {{ age }}</h1>
  175. <h3 v-else>Age: {{ age }}</h3>
  176. <!-- v-show 指令的元素始终会被渲染到HTML,它只是简单地为元素设置CSS的style属性 -->
  177. <h1 v-show="age >= 20">Age: {{ age }}</h1>
  178.  
  179. <br>
  180. <br>
  181.  
  182. <table>
  183. <thead>
  184. <tr>
  185. <th>Name</th>
  186. <th>Age</th>
  187. <th>Sex</th>
  188. </tr>
  189. </thead>
  190. <tbody>
  191. <tr v-for="person in people">
  192. <td>{{ person.username }}</td>
  193. <td>{{ person.age }}</td>
  194. <td>{{ person.sex }}</td>
  195. </tr>
  196. </tbody>
  197. </table>
  198.  
  199. <br>
  200. <br>
  201.  
  202. <!-- v-bind指令可以缩写为一个冒号 -->
  203. <ul class="pagination">
  204. <!-- pageCount是一个整数,遍历时n从1开始 -->
  205. <li v-for="n in pageCount">
  206. <a href="javascript:void(0)" v-bind:class="activeNumber === n ? 'active' : ''">{{ n }}</a>
  207. </li>
  208. </ul>
  209.  
  210. <br>
  211. <br>
  212.  
  213. <!-- v-on指令可以缩写为@符号 -->
  214. <p>
  215. <!--click事件直接绑定一个方法-->
  216. <button v-on:click="greet">Greet</button>
  217. </p>
  218. <p>
  219. <!--click事件使用内联语句-->
  220. <button v-on:click="say('Hi')">Hi</button>
  221. </p>
  222.  
  223. <br>
  224. <br>
  225.  
  226. <fieldset>
  227. <legend>
  228. Create New Person
  229. </legend>
  230. <div class="form-group">
  231. <label>Name:</label>
  232. <input type="text" v-model="newPerson.username"/>
  233. </div>
  234. <div class="form-group">
  235. <label>Age:</label>
  236. <input type="text" v-model="newPerson.age"/>
  237. </div>
  238. <div class="form-group">
  239. <label>Sex:</label>
  240. <select v-model="newPerson.sex">
  241. <option value="Male">Male</option>
  242. <option value="Female">Female</option>
  243. </select>
  244. </div>
  245. <div class="form-group">
  246. <label></label>
  247. <button @click="createPerson">Create</button>
  248. </div>
  249. </fieldset>
  250. <table>
  251. <thead>
  252. <tr>
  253. <th>Name</th>
  254. <th>Age</th>
  255. <th>Sex</th>
  256. <th>Delete</th>
  257. </tr>
  258. </thead>
  259. <tbody>
  260. <tr v-for="(person,index) in people">
  261. <td>{{ person.username }}</td>
  262. <td>{{ person.age }}</td>
  263. <td>{{ person.sex }}</td>
  264. <td :class="'text-center'">
  265. <button @click="deletePerson(index)">Delete</button>
  266. </td>
  267. </tr>
  268. </tbody>
  269. </table>
  270.  
  271. <br>
  272. <hr>
  273. </div>
  274. </body>
  275. <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  276. <script>
  277. // 这是我们的Model
  278. let exampleData = {
  279. message: 'Hello World!',
  280. yes: true,
  281. no: false,
  282. age: 28,
  283. name: 'keepfool',
  284. people: [{
  285. username: 'Jack',
  286. age: 30,
  287. sex: 'Male'
  288. }, {
  289. username: 'Bill',
  290. age: 26,
  291. sex: 'Male'
  292. }, {
  293. username: 'Tracy',
  294. age: 22,
  295. sex: 'Female'
  296. }, {
  297. username: 'Chris',
  298. age: 36,
  299. sex: 'Male'
  300. }],
  301. activeNumber: 1,
  302. pageCount: 10,
  303. newPerson: {
  304. name: '',
  305. age: 0,
  306. sex: 'Male'
  307. }
  308. };
  309.  
  310. // 创建一个 Vue 实例或 "ViewModel"
  311. // 它连接 View 与 Model
  312. // 每个Vue实例都会代理其选项对象里的data属性
  313. var vm = new Vue({
  314. el: '#app',
  315. data: exampleData,
  316. // 在 `methods` 对象中定义方法
  317. methods: {
  318. greet: function () {
  319. // 方法内 `this` 指向 vm
  320. alert(this.message)
  321. },
  322. say: function (msg) {
  323. alert(msg)
  324. },
  325. createPerson: function () {
  326. this.people.push(this.newPerson);
  327. // 添加完newPerson对象后,重置newPerson对象
  328. this.newPerson = {username: '', age: 0, sex: 'Male'}
  329. },
  330. deletePerson: function (index) {
  331. // 删一个数组元素
  332. this.people.splice(index, 1);
  333. }
  334. }
  335. })
  336. </script>
  337. </html>

推荐安装谷歌插件 vue-devtools

Vue.js——60分钟快速入门(转)的更多相关文章

  1. Vue.js 60 分钟快速入门

    Vue.js 60 分钟快速入门 转载 作者:keepfool 链接:http://www.cnblogs.com/keepfool/p/5619070.html Vue.js介绍 Vue.js是当下 ...

  2. 不会几个框架,都不好意思说搞过前端: Vue.js - 60分钟快速入门

    Vue.js——60分钟快速入门   Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的.相比于Angular.js,Vue.js提供了更加简洁.更易于理 ...

  3. Vue.js——60分钟快速入门

    Vue.js介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的.相比于Angular.js,Vue.js提供了更加简洁.更易于理解的API,使得我们 ...

  4. Vue.js——60分钟快速入门

    Vue.js介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的.相比于Angular.js,Vue.js提供了更加简洁.更易于理解的API,使得我们 ...

  5. Vue.js——60分钟快速入门(转载)

    Vue.js介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的.相比于Angular.js,Vue.js提供了更加简洁.更易于理解的API,使得我们 ...

  6. Vue.js——60分钟快速入门 开发· webpack 中文文档

    转载于:http://www.cnblogs.com/keepfool/p/5619070.html http://www.css88.com/doc/webpack2/guides/get-star ...

  7. Vue.js——60分钟快速入门(转)

    var vm = new Vue({ el: '#app', data: { people: [{ name: 'Jack', age: 30, sex: 'Male' }, { name: 'Bil ...

  8. Vue.js 60分钟快速入门

    原文链接:http://www.cnblogs.com/keepfool/p/5619070.html Vue.js介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和 ...

  9. Vue.js—60分钟快速入门

    本文摘自:http://www.cnblogs.com/keepfool/p/5619070.html Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的 ...

随机推荐

  1. Java利用原始HttpURLConnection发送http请求数据小结

    1,在post请求下,写输出应该在读取之后,否则会抛出异常. 即操作OutputStream对象应该在InputStreamReader之前. 2.conn.getResponseCode()获取返回 ...

  2. 论文阅读(Weilin Huang——【ECCV2016】Detecting Text in Natural Image with Connectionist Text Proposal Network)

    Weilin Huang——[ECCV2016]Detecting Text in Natural Image with Connectionist Text Proposal Network 目录 ...

  3. python 常用turtle

    python 常用turtle 常用命令1 import turtle turtle.bgcolor("black") 设置背景颜色 turtle.onscreenclick(x, ...

  4. /bin, /sbin & /usr/bin, /usr/sbin & /usr/local/bin, /usr/local/sbin & glibc

    操作系统为自身完成启动所需要的 /bin, /sbin 系统基本管理所需要的 /usr/bin, /usr/sbin 第三方的 /usr/local/bin, /usr/local/sbin 核心库 ...

  5. mac & ip

    mac 解决本地网络机器的通信 ip 解决不同网络间主机的通信

  6. Matlab学以致用--模拟os任务装载情况

    2012-06-08 21:26:42 用matlab来建模,仿真不同时刻os task在队列中的装载情况.输入参数如下 作为初学者,M文件写的有点长.能实现功能就算学以致用了. clear;clc ...

  7. HBase Thrift过滤语法

    摘抄自hbase ref guide 0.94: 在写本文的时候,hbase ref guide已经更新到1.2及2.0了,但是个人感觉Thrift过滤语法部分写得都没有0.94的好,省掉了examp ...

  8. C语言实例:结构体

    结构体: #include <stdio.h> #include <stdlib.h> //#pragma pack(1) typedef struct{ short i; / ...

  9. Haproxy官方文档翻译(第二章)配置Haproxy 附英文原文

    2.配置 HAProxy 2.1 配置文件格式 Haproxy的配置过程包含了3部分的参数资源:- 命令行中的参数,此种参数总是享有优先权被使用- 配置文件中global节点中的参数,此种参数是进程范 ...

  10. 3、SpringBoot 集成Storm wordcount

    WordCountBolt public class WordCountBolt extends BaseBasicBolt { private Map<String,Integer> c ...