参数验证.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  8. <link href="../css/style.css" rel="stylesheet"> </head>
  9. <body>
  10. <div id="myApp">
  11. <h1>身世之谜</h1>
  12. <show-member-info name="koma" :age="25" :detail="{address:'earth', language:'世界语'}"></show-member-info>
  13. </div>
  14. <script>
  15. Vue.component('show-member-info', {
  16. props: {
  17. name: {
  18. type: String,
  19. required: true,
  20. },
  21. age: {
  22. type: Number,
  23. validator: function (value) {
  24. return value >= 0 && value <= 130;
  25. }
  26. },
  27. detail: {
  28. type: Object,
  29. default: function() {
  30. return {
  31. address: 'US',
  32. language: 'English',
  33. };
  34. }
  35. },
  36. },
  37. template: '<div>姓名:{{this.name}}<br/>'
  38. + '年龄:{{this.age}}岁<br/>'
  39. + '地址:{{this.detail.address}}<br/>'
  40. + '语言:{{this.detail.language}} </div>',
  41. });
  42. var myApp = new Vue({
  43. el: '#myApp',
  44. });
  45. </script>
  46. </body>
  47. </html>