Vue练习

1、安装

<script src="https://unpkg.com/vue@next"></script>
简单应用
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>这是练习vue的方法</title>
    <script src="https://unpkg.com/vue@next"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
     <style>
        .class1{
            background-color: #cc0000;
        }
    </style>
</head>
<body>
<!--这是练习二:显示hello vue;{{}} v-text-->
<div id="HelloVue" class="demo1">
    <p>这是v-text更新:<span v-text="message"></span></p>
    {{message}}
</div>

<!--这是练习三 {{}} for循环-->
<div id="forApp" class="demo">

</div>


<!--这是练习四 {{}} v-html组件 -->
<div id="app" class="demo">
    <p href="#"> {{htmls}}</p>
    <br>
    <p href="#" v-html="htmls"></p>
</div>

<!--这是练习五  v-bind组件 v-if -->
<div id="v_bindApp" >
    <label>修改颜色<input type="checkbox" v-model="use" id="box1"></label>
    <br><br>
    <p v-if="use">我变身了,你就看见我了!</p>
    <div v-bind:class={"class1":use}>v-bind:class指令</div>
    <a v-bind:href="goto">小窗口,大世界,带你走遍全世界!</a>
</div>

<!--这是练习六 v-for 组件-->
<div id="v_forApp">
    <ol>
        <li v-for="list in lists" ><p v-text="list.username">这是一行</p></li>
    </ol>
</div>


<!--这是练习七 ajax获取后端数据-->
<div id="getData" v-text="lists">

</div>
<div id="appp" ><p v-text="info">fsdfs</p></div>
<script>
    <!--1-->
    const helloVueApp={
        data() {
            return { message:"Hello Vue!!"};
        }
    }
    <!--2-->
    const ForApp=Vue.createApp({
        data(){
            return{count: 5}
        },
        methods:{
            increment(){
                this.count++
            }
        }

    })

    <!--3-->
    const a=ForApp.mount('#forApp')
    for (let i=0;i<10;i++) {
        document.write(a.count)
        document.write("</br>")
        a.increment()
    //document.write(a.count)
    }

    <!--4-->
    const v_htmlApp={
        data() {
            return {htmls:"<span style='background-color: #0f91f5'>这里显示蓝色</span>"}
        }
    }

    <!--5-->
    let v_bindApp={
        data(){
            return{use:false,goto:"https://www.baidu.com"}
        }
    }

    <!--6-->
    let v_forApp={
        data(){
            return{lists:{'username':'a','username1':'b'}}
        },
        methods: {
            add:function () {
                console.log(this.lists)
            }
        }

        // getLists(){
        //     axios
        //     .get('http://192.168.1.5:8888/data1')
        //     .then((datas) => {
        //         console.log("这是结果",this.lists)
        //         this.lists.append(datas);
        //         this.lists.append(datas);
        //
        //         console.log(data.username)
        //     })
        //     .catch(function (error) {
        //         console.log(error)
        //     })
        //}
    }

    <!--7-->
    const appp = {
        data() {
            return {
                info: 'Ajax 测试!!'
            }
        },
        mounted () {
            axios
                .get('http://192.168.1.5:8888/data1')
                .then((response) => {
                    this.info=response.data.username
                    console.log("这是info:",this.info)

                })
                //console.log(response)
                .catch(function (error) { // 请求失败处理
                    console.log(error);
                });
        }
    }

Vue.createApp(appp).mount('#appp')
Vue.createApp(v_forApp).mount("#v_forApp")

Vue.createApp(helloVueApp).mount("#HelloVue")
Vue.createApp(v_htmlApp).mount("#app")
Vue.createApp(v_bindApp).mount('#v_bindApp')
//Vue.createApp(v_forApp).mount("#v_forApp")


</script>

</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的学生信息管理系统的 Vue 练习示例: 1. 在 HTML 中定义一个表格,用于展示学生信息。 ```html <table> <thead> <tr> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>成绩</th> </tr> </thead> <tbody> <tr v-for="(student, index) in students" :key="index"> <td>{{ student.name }}</td> <td>{{ student.age }}</td> <td>{{ student.gender }}</td> <td>{{ student.score }}</td> </tr> </tbody> </table> ``` 2. 在 Vue 实例中定义学生信息数据和相关操作方法。 ```js new Vue({ el: '#app', data: { students: [ { name: '张三', age: 18, gender: '男', score: 90 }, { name: '李四', age: 19, gender: '女', score: 85 }, { name: '王五', age: 20, gender: '男', score: 92 }, { name: '赵六', age: 21, gender: '女', score: 88 } ], newStudent: { name: '', age: '', gender: '', score: '' } }, methods: { addStudent: function () { this.students.push(this.newStudent); this.newStudent = { name: '', age: '', gender: '', score: '' }; }, deleteStudent: function (index) { this.students.splice(index, 1); } } }) ``` 3. 在 HTML 中添加表单和按钮,用于添加和删除学生信息。 ```html <div id="app"> <table> <!-- 表格内容同上 --> </table> <form> <label>姓名:</label> <input type="text" v-model="newStudent.name"><br> <label>年龄:</label> <input type="number" v-model="newStudent.age"><br> <label>性别:</label> <select v-model="newStudent.gender"> <option value="男">男</option> <option value="女">女</option> </select><br> <label>成绩:</label> <input type="number" v-model="newStudent.score"><br> <button type="button" @click="addStudent">添加</button> </form> <button v-for="(student, index) in students" :key="index" @click="deleteStudent(index)">删除 {{ student.name }}</button> </div> ``` 这样,一个简单的学生信息管理系统就完成了,你可以在浏览器中查看它的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值