vue组件简单实现登录退出切换

时间:2021-09-16
本文章向大家介绍vue组件简单实现登录退出切换,主要包括vue组件简单实现登录退出切换使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <div id='app'>
        <forth-login></forth-login>
        <forth-login></forth-login>
        <forth-login></forth-login>
        <forth-login></forth-login>
    </div>
    <template id="forth">
        <h1 v-if='isLogin'>
            <button @click='isLogin = !isLogin'>登录</button>
            登录/注册
        </h1>
        <h1 v-else>
            <button @click='isLogin = !isLogin'>退出</button>
            个人信息
        </h1>
    </template>
    <script>
        // 第一个参数为组件名称
        Vue.component('forth-login', {
            template: '#forth',
            data() {
                return {
                    isLogin: true
                }
            }
        })

        const vm = new Vue({
            el: '#app',
            data: {
                isLogin: true
            },
            methods: {
            },
        })
    </script>
</body>

</html>

原文地址:https://www.cnblogs.com/myqinyh/p/15302492.html