🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

mini-program-parser

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-program-parser - npm Package Compare versions

Comparing version
0.3.5
to
0.3.6
+51
-31
component/mini-parser/index.js

@@ -7,3 +7,3 @@ Component({

html: { type: String },
config: { type: Object, value: { adaptive: true } },
config: { type: Object, value: {} },
},

@@ -17,35 +17,55 @@ data: {

ready() {
const { html, config } = this.data;
const { adaptive = true } = config;
if (html) {
if (adaptive) {
this.queryTimer = setInterval(() => {
this.getContainerWidth();
}, 100);
} else {
this.setData({
renderVisible: true,
});
}
}
this.init();
},
observers: {
// 适应异步请求富文本数据
html() {
this.init();
},
},
methods: {
init() {
const { html, config } = this.data;
const { adaptive = true } = config;
if (html) {
if (adaptive) {
this.queryCount = 0;
this.queryTimer = setInterval(() => {
this.getContainerWidth();
}, 100);
} else {
this.setData({
renderVisible: true,
});
}
}
},
getContainerWidth() {
if (this.queryTimer || this.queryCount > 20) {
// 获取外层容器宽度
wx.createSelectorQuery()
.in(this)
.select(".mini-parser")
.boundingClientRect((res) => {
if (res && res.width > 0) {
this.queryTimer = null;
this.setData({
containerWidth: res.width,
renderVisible: true,
});
} else {
this.queryCount += 1;
}
})
.exec();
if (this.queryTimer) {
if (this.queryCount < 10) {
// 获取外层容器宽度
wx.createSelectorQuery()
.in(this)
.select('.mini-parser')
.boundingClientRect(res => {
if (res && res.width > 0) {
clearInterval(this.queryTimer);
this.queryTimer = null;
this.setData({
containerWidth: res.width,
renderVisible: true,
});
} else {
this.queryCount += 1;
}
})
.exec();
} else {
// 找不到外层元素时,将自适应设置为false
clearInterval(this.queryTimer);
this.setData({
config: { ...this.data.config, adaptive: false },
renderVisible: true,
});
}
}

@@ -52,0 +72,0 @@ },

{
"name": "mini-program-parser",
"version": "0.3.5",
"version": "0.3.6",
"scripts": {

@@ -5,0 +5,0 @@ "dev": "rollup -c ./rollup.dev.config.js --watch",