-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
初始化数据时ie8报错 #422
Comments
如果不是异步,你为什么不直接把数据直接在 data 里声明呢? |
上代码吧。我试了下没发现问题。这是我的代码 var Label = san.defineComponent({
template: '<b>{{text}}</b>',
inited: function () {
if (this.data.get('num') === 1) {
this.data.set('text', 'one');
}
}
});
var MyComponent = san.defineComponent({
template: '<div><x-l num="{{num}}"/></div>',
components: {
'x-l': Label
}
})
var myComponent = new MyComponent({
data: {
num: 1
}
});
myComponent.attach(document.body) 另外,你的场景感觉应该通过 computed 来做。 |
sorry,我没描述清楚,其实我遇到问题的是下面这段代码,这个直接在 ie8是没问题的,但是我用 webpack 打包时用import san from 'san'这种方式引入后相同的代码会报错,这是我真正有疑惑的地方。 没问题的代码
报错的代码报错信息:HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
|
可能是 Object.defineProperty 的问题 |
是要先引入下面这段代码吗?我引入后重新打包好像还是会报错。。
|
我可能猜错了。 你看看你最终输出的html,script是不是位于没闭合标签内 |
这是生成的 html
另外我刚才把import 换成了require,打包也是一样的结果
但是我只要把 set 放到 setTimeout 里面,就不会报错
|
到这步,信息量太少了,我无法判断出来。 你只能根据错误信息定位到static/js/main.c12fe78d35e4e7ee4664.js的运行位置,再根据当前dom的状态,跟踪到底是哪里出问题了 |
好 |
https://github.com/sjiangbei/san-test @errorrik 传上去了,如果有时间辛苦看一下 0.0 |
IE9- 环境下,不支持 webpack4 打包代码中的 getter/setter 访问器属性。建议更换其他构建工具来进行打包构建。 |
额 好像和 webpack4没关系把? 我降级成 webpack3和2 还是同样的问题。例子也上传了@errorrik https://github.com/sjiangbei/san-test |
@sjiangbei webpack打包出来的代码里,有这么一段,对setImmediate进行模拟实现:在html element上append一个script function installReadyStateChangeImplementation() {
var html = doc.documentElement;
registerImmediate = function(handle) {
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var script = doc.createElement("script");
script.onreadystatechange = function () {
runIfPresent(handle);
script.onreadystatechange = null;
html.removeChild(script);
script = null;
};
html.appendChild(script);
};
} san 的 nextTick 是这么实现的 if (typeof setImmediate === 'function') {
setImmediate(nextHandler);
}
// 用MessageChannel去做setImmediate的polyfill
// 原理是将新的message事件加入到原有的dom events之后
else if (typeof MessageChannel === 'function') {
var channel = new MessageChannel();
var port = channel.port2;
channel.port1.onmessage = nextHandler;
port.postMessage(1);
}
// for native app
else if (isNativePromise) {
Promise.resolve().then(nextHandler);
}
else {
setTimeout(nextHandler, 0);
} 你的代码 解决办法很简单,把你初始化的代码放到 |
业务场景
当子组件需要根据父组件传入的数据来格式化自己的一些默认数据时,会调用一些格式化子组件数据的方法。
san版本
3.7.6
问题
1.在inited/created/attached三个生命周期钩子函数格式化数据时【就是执行 类似于this.data.set('xxx', ' xxx' )】时,ie8会报错
HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
2.格式化方法在以上三个钩子函数中放在 setTimeout 函数中就不会报错。
期望结果
在上面的钩子函数中的一个方法里面,正常的格式化数据应该在 ie8上不报错,不需要放到setTimeout里面。
The text was updated successfully, but these errors were encountered: