【发布时间】:2021-10-20 10:39:10
【问题描述】:
我有一个用 vuejs 编写并由 firebase 托管的网站。昨天我设法缩小了网站只会在移动设备上显示空白白页的问题,这归结为我在组件的一个数据函数中声明的这两个对象:
re: {
youtube: /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*)/,
id: /(?<=\?v=)\w*(?=[^#\&\?]*)/,
//for timestamp at end of youtube urls
urlTimestamp: /(?<=&t=)((?:[0-9]{1,2})h)?((?:[0-9]{1,3})m)?((?:[0-9]{1,5})s)?/g,
// for checking if timestamp string is valid
timestamp: /^([0-9]{1,2}h)?([0-9]{1,3}m)?([0-9]{1,5}s)?$/g,
},
rules: {
name: [
v => !!v || 'Required'
],
url: [
v => !v || v && /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*)/.test(v) || 'Invalid URL',
v => !v || /(?<=\?v=)([^#\&\?]*)/.test(v) && v.match(/(?<=\?v=)([^#\&\?]*)/)[0].length === 11 || 'Video ID must be 11 characters'
],
timestamp: [
v => !v || v && (/^([0-9]{1,2}h)?([0-9]{1,3}m)?([0-9]{1,5}s)?$/g).test(v) || 'Invalid format',
],
},
(有两个时间戳正则表达式,因为一个从 youtube url 的末尾提取时间戳,另一个检查时间戳字符串本身是否有效)
当我删除它们时,网站显示正常。仅删除一个或另一个会导致相同的白页。在此组件的“监视”函数中使用正则表达式也会导致同样的错误。我不知道这里可能是什么问题。
【问题讨论】:
标签: javascript regex vue.js mobile-website