Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

Vue2.2 props验证总是出错,我开始怀疑人生

1.props验证总是报错
2.相关代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="../lib/vue.js"></script>
</head>
<body>
<div id="app">
    <example :propC="100"></example>
</div>
</body>
<script type="text/javascript">

    Vue.component('example', {
        props: {
            propC: {
                type: String,
                required: true
            },
            propD: {
                type: Number,
                default: 100
            }
        },
        template: '<h1>{{propC}}-{{propD}}</h1>'
    })

    var vm = new Vue({
        el: '#app',
        data: {
            msg: 'hello world',
            num: 100
        }
    })


</script>
</html>
  1. 运行结果:
    图片描述


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

html标签属性不识别大小写 你 propC 要写成 prop-c


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...