【发布时间】:2019-08-02 12:16:10
【问题描述】:
首先,我是 Vue 的新手,所以请多多包涵。 我正在研究由其他人编写的代码库。该应用程序非常简单,只是一个收集数据的表格。其中一个字段是邮政编码字段,并具有以下验证:
postcodeRules: [v => !!v || "Please enter your postcode"]
如果我理解正确,它所做的就是针对空字段进行验证。我想添加一个方法被调用来验证这个字段,例如:
postcodeRules: [v => !!v || "Please enter your postcode", v => this.checkPostcode(v) || "Postcode not valid"]
checkPostcode() 会调用外部 API,但我收到错误:TypeError: Cannot read property 'checkPostcode' of undefined。
我也试过了
postcodeRules: [v => !!v || "Please enter your postcode", v => checkPostcode(v) || "Postcode not valid"]
这是我的全部代码:https://gist.github.com/WagnerMatos/f884e97fe47c4553e6e5aaf3ebbec792
知道如何让它工作吗?
提前致谢!
编辑 这是模板代码:https://gist.github.com/WagnerMatos/c2e45bdf00db06f98a109e6313dd35a8
【问题讨论】:
标签: vue.js