日升昌面试题
<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>