Vue.js 简单demo

demo1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- Source -->
    <script src="js/axios.js"></script>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="indexPage">
        <p v-for="post in posts">{{post}}</p>
        <button @click="getValue">获取后端数据</button>
    </div>

    <script>
        var vm = new Vue({
            el: document.getElementById("indexPage"),
            mounted() {
                this.getValue();
            },
            data:{
                posts:[]
            },
            methods:{
                getValue:function(){
                    var that = this;
                    axios.get("https://localhost:5001/Post/GetPost").then(function(res){
                        that.posts =res.data;
                    })
                }
            }
        });
    </script>
</body>
</html>

demo2

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/axios.js"></script>
    <script src="js/vue.js"></script>
</head>

<body>
    <div id='loginPage'>
        <div class="login-pad">
            <h3>BBS论坛登录</h3>
            <p>
                <!-- 事件的绑定,在触发事件前面加 @ -->
                <!-- 属性的绑定,在需要绑定的属性前面加 : -->
                <!-- 注意!属性绑定是单向的,只能从vue对象绑定到标签 -->
                <!-- 如果要双向就要用 v-model ,但是v-model只是作用在value上,当然这样说不严谨,但是目前请这么记忆-->
                <input type="text" placeholder="请输入用户账号" v-model="userNo">
            </p>
            <p>
                <input type="password" placeholder="请输入用户密码" v-model="password">
            </p>
            <p class="error-box">{{errorMsg}}</p>
            <p>
                <button @click="login">登录</button>
            </p>
        </div>
    </div>

    <script>
        var vm = new Vue({
            el: "#loginPage",//document.getElementById("loginPage")
            data:{
                userNo:"2251610468",
                password:"123456",
                errorMsg:""
            },
            methods: {
                login:function(){
                    var that = this;
                    axios.get("https://localhost:5001/Login/CheckLogin?userNo="+this.userNo+"&password="+this.password).then(function (res) {
                       if(res.data == true){
                           location.href = "/index.html"
                       }else{
                           that.errorMsg = "用户名或密码错误";
                        //    alert("用户名或密码错误")
                       }
                    })
                }
            },
        })
    </script>

    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .login-pad{
            width: 566px;
            height: 260px;
            margin-left: auto;
            margin-right: auto;
            margin-top: 10%;
            border: 1px solid #ccc;
            box-shadow: 10px 10px 10px rgb(100, 100, 100);
            border-radius: 4px;
        }
        h3{
            text-align: center;
            margin-top: 10px;
            margin-bottom: 20px;
        }
        p{
            text-align: center;
            margin-bottom: 20px;
        }
        .error-box{
            width: 300px;
            margin-left: auto;
            margin-right: auto;
            text-align: left;
            color:red;
            font-size: 12px;
        }
        input{
            width: 300px;
            height: 30px;
        }
        button{
            height: 30px;
            width: 300px;
        }
    </style>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值