css
html
前端
vue
angularjs
es6
web
vue-router
vuex
編程
<div class="mydiv"> <lable>用戶名:</lable> <input type="text" data-name="uname" value="hello"/> </div>
var arr = []; for(var i=0;i<10;i++){ arr[i]=function(){ return i; } } var res=arr[3]() console.log(res);
var arr = []; for(var i=0;i<10;i++){ arr[i]=(function(i){ return function(){ return i; } })(i) } var res=arr[3]() console.log(res); // 這樣一來數組的每一個函數就處於一個當即執行函數的函數做用域中,該當即執行函數傳入i,其實for循環執行了以下代碼: // array[0]=(function(i){ // return function(){ // return i; // } // })(0); // array[1]=(function(i){ // return function(){ // return i; // } // })(1); // 這樣一來,數字組中每一個函數對應一個單獨的函數做用域(當即執行函數的)這裏共建立了10個函數做用域,這些函數做用域裏的i值就是執行時候傳入的0……9,當執行 // array[3]();時候函數訪問的i值是其對應的當即執行函數做用域裏的 i,而不是全局的i值,這樣咱們就獲得了預期的效果。 // 說獲得這裏咱們簡單來講一下閉包,閉包能夠理解爲一個閉包就是一個沒有釋放資源的棧區,棧區內的變量處於激活狀態。上面的例子中for循環在執行時系統分配內存,js執行線程建立執行棧區,執行
service.js代碼以下 let myService={ /** *功能:獲取教師id,即tid *參數:tno--教師編號 */ getTcId:function (param) { let result=$.post('http://localhost:8080/getTcId',param); return result; }, /** *功能:獲取老師詳細信息 *參數:tid--教師id */ getTcInfo:function (param) { let result=$.post('http://localhost:8080/getTcInfo',param); return result; } } index.html以下 <button>獲取張老師信息</button> <div class="tinfo"></div> <script src="service.js"></script> <script> $('button').click(function () { let param={tno:20160808}; getTcId(param).then(function (rep) { let tid=rep.tid; let param={tid:tid} getTcInfo(param).then(function (rep) { $('tinfo').html(`老師的詳細信息爲:${rep}`) }) }) }) </script>
$('button').click(async function () {
let tid=(await getStudent({tno:20160808})).tid;
let tinfo=await getStudent({tid:tid})
$('tinfo').html(`老師的詳細信息爲:${rep}`)
})
//父組件中 <child message="hello!"></child> //子組件中 <template> <div> {{message}} </div> </template> export default { name: "baseLayer", props:['message'] } /*須要注意的是,子組件不能修改父組件的props 由於一個父組件下可能有多個子組件,若是某個子組件修改了父組件傳遞的props, 極可能致使其餘子組件也就跟着變化,最終致使整個應用的狀態難以管理和維護 因此不容許子組件修改props*/
//父組件中 <template> <div class="father"> <child v-on:result="clickChild"></child> </div> </template> <script> import child from '@/compoment/child' export default { name:'father', components:{child}, methods:{ clickChild(type){ alert(type) } } } </script> //子組件中 <template> <div> <button v-on:click="clickBtn(true)">肯定</button> </div> </template> export default { name: "child", methods:{ clickBtn(b){ //監聽result變化, 併發出通知 //(在angularjs中叫作廣播,angularjs提供了emit, //broadcast和$on服務用於向父中傳遞消息) this.$emit('result', b); } }
http://www.cnblogs.com/flyings/p/9022583.html
export default new Router({ routes: [ { path: '/', name: 'home', component: home }, { path: '/blogDetail/:bid', name: 'BlogDetail', component: blogDetailCmp }]
import mytoast from './toast'; export default { install:function(Vue){ //生成一個Vue的子類,同時這個子類也就是組件.並生成一個該子類的實例 const Toast = Vue.extend(mytoast); let toast = new Toast(); // 將這個實例掛載在我建立的div上, 並將此div加入全局掛載點內部 toast.$mount(document.createElement('div')) document.body.appendChild(toast.$el) //掛在到全局 Vue.prototype.$toast=function (msg,time) { toast.msg=msg; toast.open(); if(time){ setTimeout(function () { toast.close(); },time) } }
import modal from './plugin/modal/index' Vue.use(modal)//啓用本身的插件
// 註冊一個全局自定義指令 `v-focus` Vue.directive('focus', { // 當被綁定的元素插入到 DOM 中時…… inserted: function (el) { // 聚焦元素 el.focus() } }) directives: { focus: { // 指令的定義 inserted: function (el) { el.focus() } } }
<input v-focus>