(一)propsData Option全局扩展的数据传递

2018-02-15  本文已影响0人  我拥抱着我的未来

本节知识点

概述

使用

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
   <div id="app">
       <hello></hello>
   </div>
</body>
<script>
    var hello = Vue.extend({
        template:`<p style="color:red;">{{message}}这个就是属性{{a}}</p>`,
        data:function(){
            return {
                message:"2018新年好"
            }
        },
        props:['a']
    })
   new hello({propsData:{a:1}}).$mount("hello");
</script>
</html>

第二种用法验证

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
   <div id="app">
       <hello></hello>
   </div>
</body>
<script>
    var hello = Vue.extend({
        template:`<p style="color:red;">{{message}}这个就是属性{{a}}</p>`,
        data:function(){
            return {
                message:"2018新年好"
            }
        },
          props:{
            count1:{
                type:Number,
                default:0,
                require:true
            }
        }
    })
   new hello({propsData:{a:1}}).$mount("hello");
</script>
</html>
上一篇下一篇

猜你喜欢

热点阅读