2.1.1 ES6的簡單語法;javascript
2.1.2 強類型與弱類型的變量聲明;css
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javascript"> //let聲明的變量是塊級做用域時候,不能重複聲明; //let聲明的變量,是塊級做用域,不能重複聲明; { // let a = 12; // let a = 13; // var a = 12; // var a = 13; } //console.log(a); // var a = []; // for(let i = 0; i < 10; i++) { // a[i] = function() { // console.log(i); // }; // } // a[6](); //var~10,let~6;r //let不存在變量提高;Js語言叫作「僞面向對象」; // console.log(foo); //輸出undefined; // var foo = 2; //const用來聲明常量(即只讀的變量,好比π), 一旦聲明, 當即初始化, 且不能重複聲明; const PI = 3.1415926537 PI PI = 3 //報錯!Uncaught TypeError: Assignment to constant variable </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="text/javascript"> //js中拼接字符串和變量; var a = 1; var b = 2; var str1 = "哈哈哈" + a + "嘿嘿嘿" + b; //推薦使用反引號; var str2 = `哈哈哈${a}嘿嘿嘿${b}13811221893` ; console.log(str1,str2); </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>03-箭頭函數</title> </head> <body> <script type="text/javascript"> // var f = function (a) { // return a // // }; // f(1) //箭頭函數; // var f = (a) => { // return a; // } //function(){} <==> () => {}//箭頭函數,聯想Python的三元運算; //字面量方式建立對象; var person1 = { name: '日天', age: 30, fav: function () { //console.log('喜歡av1');//分號是結束的標記; //使用時候定義的對象; console.log(this); console.log(arguments); console.log(this.name); } }; person1.fav(); //以上改爲箭頭函數; //使用箭頭函數的第1個坑! var person2 = { name: '日天', age: 30, fav: () => { //console.log('喜歡av2');//分號是結束的標記; //改爲箭頭函數後,此時,this就變成了定義時候所使用的對象;指向了咱們的window; console.log(this); console.log(this.name); } }; person2.fav(); //使用箭頭函數的第2個坑!arguments不能使用! var person3 = { name: '日天', age: 30, fav: () => { //console.log('喜歡av2');//分號是結束的標記; //改爲箭頭函數後,此時,this就變成了定義時候所使用的對象;指向了咱們的window; console.log(this); //console.log(arguments);#Uncaught ReferenceError: arguments is not defined console.log(this.name); } }; person3.fav(1, 2, 3, 4, 5); </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>04-對象的單體模式</title> </head> <body> <script type="text/javascript"> var person = { name: '崔曉昭', age: 26, //Vue的課程中,有不少這樣的寫法; fav() { console.log(this); } }; person.fav(); </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>06-ES6的面向對象</title> </head> <body> <script type="text/javascript"> //構造函數的方式建立類,此方法稱之爲面向對象; // function Animal(name, age) { // this.name = name; // this.age = age; // } // // Animal.prototype.showName = function () { // console.log(this.name) // }; // Animal.prototype.showName = function () { // console.log(this.name) // }; // Animal.prototype.showName = function () { // console.log(this.name) // }; // Animal.prototype.showName = function () { // console.log(this.name) // }; // var dog = new Animal('天晴天朗', 26); class Animal { constructor(name, age) { this.name = name; this.age = age; }//此處沒有逗號,只有在類中才有此種寫法! showName() { console.log(this.name) } } var d = new Animal('崔曉絲', 28); d.showName(); </script> </body> </html>
https://nodejs.org/download/release/v6.10.3/html
cuixiaozhaodeMacBook-Pro:~ cuixiaozhao$ cd /Users/cuixiaozhao/WebstormProjects/Vue_Learn/02-Lessons cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ pwd /Users/cuixiaozhao/WebstormProjects/Vue_Learn/02-Lessons cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ ls cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ mkdir images cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ mkdir js cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ mkdir css cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ mkdir fonts cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ pwd /Users/cuixiaozhao/WebstormProjects/Vue_Learn/02-Lessons cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ cl -bash: cl: command not found cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ clear cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ pwd /Users/cuixiaozhao/WebstormProjects/Vue_Learn/02-Lessons cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$ npm init This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help json` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg>` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. package name: (02-lessons) 02 version: (1.0.0) 1.0.2 description: Learn npm entry point: (index.js) test command: git repository: tqtl911@163.com keywords: 19930911cXS author: cuixiaozhao license: (ISC) None Sorry, license should be a valid SPDX license expression (without "LicenseRef"), "UNLICENSED", or "SEE LICENSE IN <filename>". license: (ISC) About to write to /Users/cuixiaozhao/WebstormProjects/Vue_Learn/02-Lessons/package.json: { "name": "02", "version": "1.0.2", "description": "Learn npm", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "tqtl911@163.com" }, "keywords": [ "19930911cXS" ], "author": "cuixiaozhao", "license": "ISC" } Is this OK? (yes) yes cuixiaozhaodeMacBook-Pro:02-Lessons cuixiaozhao$
https://cn.vuejs.org/v2/guide/installation.html前端
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Title</title> </head> <body> <div id="app"> <h3>{{title}}</h3> </div> <script src="vue.js"></script> <script> //一、建立Vue實例對象; //二、參數; var app = new Vue({ el: "#app", data: { title: "崔曉昭" } }) </script> </body> </html>
var person = {vue
name:"張三",java
fav(){node
}react
}jquery
Last login: Fri Sep 14 15:29:56 on ttys001 cuixiaozhaodeMacBook-Pro:~ cuixiaozhao$ npm install -g cnpm --registry=https://registry.npm.taobao.org npm WARN deprecated socks@1.1.10: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0 /usr/local/bin/cnpm -> /usr/local/lib/node_modules/cnpm/bin/cnpm + cnpm@6.0.0 added 632 packages from 842 contributors in 36.206s cuixiaozhaodeMacBook-Pro:~ cuixiaozhao$
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>StudyVue</title> </head> <body> <div id="app"> <!--插值語法:react {} angular{{}} {%%} <% = %>--> <h3>{{msg}}</h3> <h3>{{1>2?"真的":"假的"}}</h3> <div v-if='show'>哈哈哈</div> <button v-on:click="clickHandler">切換</button> </div> <script type="text/javascript" src="vue.js"></script> <script type="text/javascript"> //Vue的實例化對象; //Vue的設計模式——MVVM:Model、View、ViewModel; //指令系統:v-*; var app = new Vue({ el: "#app", data: { msg: "今天學習Vue", show: false, }, methods: { clickHandler: function () { // alert(11) console.log(this); this.show = !this.show } } }); console.log(app); console.log(app.$el); console.log(app.msg);//此方法,不推薦,失去了使用Vue的意義! </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>StudyVue</title> <style type="text/css"> .box { width: 100px; height: 100px; background: red; } .box2 { width: 100px; height: 100px; background: green; } </style> </head> <body> <div id="app"> <!--插值語法:react {} angular{{}} {%%} <% = %>--> <h3>{{msg}}</h3> <h3>{{1>2?"真的":"假的"}}</h3> <div v-if='show'>哈哈哈</div> <button v-on:click="clickHandler">切換</button> <div v-if="Math.random() > 0.5 "> Now you see me! </div> <div v-else> Now you don't </div> <h3 v-show="isShow" v-bind:title="title">我是一個三級標題</h3> <img v-bind:src="imgSrc" v-bind:alt="time"> <div class="box " v-bind:class="{box2:isGreen,box3:isYellow}"></div> <button @click="changeColor">切換顏色</button> <br> <button v-on:click="count+=1">加上{{count}}</button> <!--//聲明式的指令:--> <!--//命令式的指令;--> </div> <script type="text/javascript" src="vue.js"></script> <script type="text/javascript"> //Vue的實例化對象; //Vue的設計模式——MVVM:Model、View、ViewModel; //指令系統:v-*; //Vue的核心思想:數據驅動視圖!雙向的數據綁定:數據《===》視圖; var app = new Vue({ el: "#app", data: { msg: "今天學習Vue", show: false, isShow: true, title: "哈哈哈哈", imgSrc: "./canglaoshi.JPG", time: `頁面加載於${new Date().toLocaleDateString()}`, isGreen: true, isYellow: true, count: 0 }, methods: { clickHandler: function () { // alert(11) console.log(this); this.show = !this.show }, changeColor() { this.isGreen = !this.isGreen } } }); console.log(app); console.log(app.$el); console.log(app.msg);//此方法,不推薦,失去了使用Vue的意義! //簡便寫法即語法糖:v-bind~: v-on:click ~ @click </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>StudyVue</title> <style type="text/css"> * { padding: 0; margin: 0; } .box { width: 100px; height: 100px; background: red; } .box2 { width: 100px; height: 100px; background: green; } /*.lunbo{*/ /*width: 180px;*/ /*overflow: hidden;*/ ul { width: 180px; overflow: hidden; list-style: none; margin-left: 10px; } ul li { float: left; width: 30px; height: 30px; background: purple; margin-left: 10px; text-height: 30px; text-align: center; color: white; } </style> </head> <body> <div id="app"> <!--插值語法:react {} angular{{}} {%%} <% = %>--> <h3>{{msg}}</h3> <h3>{{1>2?"真的":"假的"}}</h3> <div v-if='show'>哈哈哈</div> <button v-on:click="clickHandler">切換</button> <div v-if="Math.random() > 0.5 "> Now you see me! </div> <div v-else> Now you don't </div> <h3 v-show="isShow" v-bind:title="title">我是一個三級標題</h3> <img v-bind:src="imgSrc" v-bind:alt="time"> <div class="box" v-bind:class="{box2:isGreen,box3:isYellow}"></div> <button @click="changeColor">切換顏色</button> <br> <button v-on:click="count+=1">加上{{count}}</button> <!--//聲明式的指令:--> <!--//命令式的指令;--> <div class="lunbo"> <img :src="currentSrc" @mouseenter="closeTimer" @mouseleave="openTimer"> <ul> <li v-for="(item,i) in imgArr" @click="currentHandler(item)">{{i+1}}</li> </ul> <button @click="nextImg">下一張</button> <button @click="beforeImg">上一張</button> </div> </div> <script type="text/javascript" src="vue.js"></script> <script type="text/javascript"> //Vue的實例化對象; //Vue的設計模式——MVVM:Model、View、ViewModel; //指令系統:v-*; //Vue的核心思想:數據驅動視圖!雙向的數據綁定:數據《===》視圖; var app = new Vue({ el: "#app", //小的,假的數據庫; data: { msg: "今天學習Vue", show: false, isShow: true, title: "哈哈哈哈", imgSrc: "./canglaoshi.JPG", time: `頁面加載於${new Date().toLocaleDateString()}`, isGreen: true, isYellow: true, count: 0, imgArr: [ {id: 1, src: './1.jpeg'}, {id: 2, src: './2.jpeg'}, {id: 3, src: './3.jpeg'}, {id: 4, src: './4.jpeg'} ], currentSrc: "./1.jpeg", currentIndex: 0, timer: null, }, //cookie 和session; // created() { // this.timer = setInterval(this.nextImg, 2000) // }, methods: { clickHandler: function () { // alert(11) console.log(this); this.show = !this.show }, changeColor() { this.isGreen = !this.isGreen }, currentHandler(item) { this.currentSrc = item.src }, nextImg() { if (this.currentIndex == this.imgArr.length - 1) { this.currentIndex = -1; } this.currentIndex++; this.currentSrc = this.imgArr[this.currentIndex].src; }, closeTimer() { clearInterval(this.timer) }, openTimer() { this.timer = setInterval(this.nextImg, 1000) }, beforeImg() { if (this.currentIndex == this.imgArr.length - 1) { this.currentIndex = -1; } this.currentIndex--; this.currentSrc = this.imgArr[this.currentIndex].src; }, } }) ; console.log(app); console.log(app.$el); console.log(app.msg);//此方法,不推薦,失去了使用Vue的意義! //簡便寫法:v-bind~: v-on:click ~ @click </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>02-計算屬性</title> </head> <body> <div id="computed"> <div> <!--設置模板語法的初衷是應對簡單運算!--> <!--{{msg.split('').reverse().join('')}}--> <!--使用computed中的reverseStr代替;--> {{reverseStr}} </div> <button @click="clickHandler">修改</button> </div> <script type="text/javascript" src="vue.js"></script> <script> var com = new Vue({ el: "#computed", data: { msg: 'Hello World!' }, methods: { clickHandler() { //this.msg = 'Hello LuffyCity!' console.log(this.reverseStr); this.reverseStr = 'Hello LuffyCity' } }, computed: { //默認只有getter方法; //計算屬性能夠看作是一個watch; // reverseStr() { // return this.msg.split('').reverse().join(''); // } reverseStr: { set: function (newValue) { this.msg = newValue }, get: function () { return this.msg.split().reverse().join(''); }, } } }) </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>02-計算屬性</title> </head> <body> <!--事件修飾符!--> <form id="computed" @summit.prevent> <!--數據的雙向綁定!--> <!--<input type="text" v-model="msg">--> <input type="text" v-model.lazy="msg"> <input type="number" v-model.number="msg"> <input type="submit" name="" value="提交"> <!--<input type="text" v-bind:value='msg' @input='msgChange'>--> <h3>{{msg}}</h3> </form> <script type="text/javascript" src="vue.js"></script> <script> var com = new Vue({ el: "#computed", data: { msg: '123' }, methods: { msgChange(e) { console.log(e.target.value); this.getValue = e.target.value; } //$.ajax() 在Vue中不使用,xmlhttpRequest axios ajax技術 }, computed: { getValue: { set: function (newValue) { this.msg = newValue; }, get: function () { return this.msg; } } } }) </script> </body> </html>