2017年6月30日 星期五

(倚靠vue,是你自己不會架構,別人都幫你寫好好,屌吹個屁).....切換子模版

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <script src="../../js_script/vue-2.3.0.js"></script>
    <script>
        var Home = Vue.component('Home', {
            template: `<div>
                <div>Home</div>
                <div>{{age}}</div>
            </div>`,
            props: ['age'],
            data: function() {
                return {
                    name: 'home'
                }
            }
        });

        var Xman = Vue.component('Home', {
            template: `<div>
                <div>Xman</div>
                <div>{{age}}</div>
            </div>`,
            props: ['age'],
            data: function() {
                return {
                    name: 'xMan'
                }
            }
        });
    </script>
</head>

<body>
    <div id="app">
        <p>
            <input type="radio" v-model="current" value="home" />
            <input type="radio" v-model="current" value="xman" />
        </p>
        <component :is="current" :age="age"></component>
    </div>
    <script>
        new Vue({
            el: '#app',
            data: {
                current: 'home',
                age: 15
            },
            components: {
                home: Home,
                xman: Xman
            }
        });
    </script>
</body>

</html>