Vue的面试题

1、$on 和$emit 实现原理


 <my-component @my-event='fb'></my-component> =>ast  =>vnode

  this.$emit('my-event');



 Vue.prototype.$on=function(event:string|Array<string>,fn:Function):Component{

    const vm:Component=this;

    if(Array.isArray(event)){

        for(let i=0;l=event.length;i<l;i++){

            vm.$on(event[i],fn)

        }

    }else{



    }

}

 

2、$parent 和 $children 的实现原理

 

3、Vue 中的inject和provide的原理

 

4、谈一下你对vuex的理解

// 单向数据流,数据集中管理,多组件共享,数据无法持久化

// 如果实现数据的响应式

 

/****

 * 先表达出单向数据流的概念,及整个vuex的运行流程

 * 状态集中管理,实现多组件状态共享

 * Vuex的原理是通new Vue产生实例,达到响应式数据变化的目的

 */

 

5、Vue组件中写name选项有哪些好处和作用?

/**

 * - 写name的好处是可以给组件增添名字, vm.$options.name 获取名字

 * - 这里我们之前实现过$broadcast及$dispatch 都是根据名字来查找对应的组件 父辈和子辈来提交数据

 */

 

6、v-if v-model v-for 

let compiler =require("vue-template-compiler");



// v-if

const ast1=compiler.compile("<div v-if='false'></div>");

console.log(ast1.render);



// v-for 

const ast2=compiler.compile('<div v-for="i in 3"></div>');

console.log(ast2.render);



// v-model

const ast3=compiler.compile('input v-model="name"');

console.log(ast3.render);



// component

const ast4=compiler.compile('<component v-model="name"></component>');

console.log(ast4.render);



/* 

with(this){return (false)?_c('div'):_e()}

with(this){return _l((3),function(i){return _c('div')})}

with(this){return _c("div")}

with(this){return _c('component',{model:{value:(name),callback:function ($$v) {name=$$v},expression:"name"}})}

 */

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vues

刚好遇见你

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值