var isUrl = (rule, value, callback) => {
var matchUrl = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/
if (value.trim().length > 1000) {
callback(new Error(‘不能超过1000个字符‘))
$(this.$refs.qrcode).empty()
return
} else {
if (!matchUrl.test(value.trim())) {
callback(new Error(‘不是正确网址‘))
$(this.$refs.qrcode).empty()
return
}
}
}
2:引用规则
rules: {
url: [
{ validator: isUrl, trigger: ‘change‘ }
]
}