PeraMika提出了一个问题:Default values for Vue component props & how to check if a user did not set the prop?,或许与您遇到的问题类似。
回答者craig_h给出了该问题的处理方式:
Vue
allows for you to specify a default prop
value and type
directly, by making props an object (see: https://vuejs.org/guide/components.html#Prop-Validation):
props: { year: { default: 2016, type: Number } }
If the wrong type is passed then it throws an error and logs it in the console, here's the fiddle:
https://jsfiddle.net/cexbqe2q/
希望本文对你有帮助,欢迎支持JavaScript中文网