修正不能匹配全部CSS单位的问题

This commit is contained in:
ansonhorse 2019-04-22 20:30:37 +08:00
parent 04af0d3497
commit b3a7b78f5b
1 changed files with 2 additions and 2 deletions

View File

@ -70,9 +70,9 @@ export default {
*/
containerStyle() {
const style = {}
if (/^[\d]+(\.\d+)?$/.test(this.width)) { // Matches `100`, `'100'`
if (/^[\d]+(\.[\d]+)?$/.test(this.width)) { // Matches `100`, `'100'`
style.width = `${this.width}px`
} else if (/^[\d]+(\.\d+)?([a-z]{2}|%)$/.test(this.width)) { // Matches `100px`, `100rem`, `70%`, etc
} else if (/^[\d]+(\.[\d]+)?([a-z]{2,4}|%)$/.test(this.width)) { // Matches `100px`, `100rem`, `70%`, etc
style.width = `${this.width}`
}
return style