help wanted
Description
-
v-show 在自定义组件或label标签上使用时无效。
-
貌似不能通过Vue.Component注册全局组件。
-
在App.vue中,钩子函数中无法通过this直接访问定义过的属性,而需要通过this.rootVM.$options才能拿到 ( getApp()返回的对象中也没有之前定义过的东西,这让旧的代码无法兼容啊)。 示例如下:
// App.vue
export default {
onLaunch() {
console.log(this.foo); // 拿不到这个foo呀
console.log(this.rootVM.$options.foo); // 终于拿到了,但是太麻烦了吧!!!
},
foo: 'foo'
});
// index.js
const app = getApp();
console.log(app.foo); // 拿不到这个foo
console.log(app.rootVM.$options.foo); // 拿到了,麻烦了点吧!!!
// 如果要优化的话可能是修改doCallHook这个函数吧
function doCallHook (vm, hook, options) {
var handlers = vm.$options[hook] || [];
if (!Array.isArray(handlers)) {
handlers = [handlers];
}
return handlers.reduce(function (res, handler) {
if (vm.$options.mpType === 'app') {
return handler.call(vm.$options, options) // 整这么三句吧
}
return handler.call(vm, options)
}, undefined)
}