1、以下会打印:(C)
new Vue({
data: { a: 1, b: 2 },
created: function () {
console.log(this.a)
},
mounted(){
console.log(this.b)
}
})
A、1,2 B、2 C、1 D、2,1
解析:mounted 为节点挂载之后才执行的钩子函数,因为当前并无节点挂载,故打印的为C。
2、以下获取动态路由{ path: ‘/user/:id’ }中id的值正确(A)
A、this.$route.params.id
B、this.route.params.id
C、this.$router.params.id
D、this.router.params.id
3、 Class 与 Style 如何动态绑定?
参考网址:https://cn.vuejs.org/v2/guide/class-and-style.html
4、下面程序的输出?
const promise = new Promise((resolve, reject) => { resolve('success1'); reject('error'); resolve('success2'); }); promise.then( (res) => { console.log('then:', res); } ).catch( (err) => { console.log('catch:', err); } );
解析:该程序没有错误所以reject()函数不调用,第一个回调就是正确的,所以不许往下进行,故输出:
'then:', success1