zoukankan      html  css  js  c++  java
  • vue访问页面时自动触发函数

    使用 mounted:function () {} 访问页面时自动触发函数内容

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Index</title>
        <script src="static/js/vue.js"></script>
        <script src="static/js/axios.min.js"></script>
    </head>
    <body>
    <div id="get_host_data">
        <button @click="GetHostData">获取数据</button>
        <table class="table table-bordered table-hover table-striped">
            <thead>
            <tr>
                <td>ID</td>
                <td>版本包</td>
                <td>md5</td>
            </tr>
            </thead>
            <tbody>
                <tr v-for="(item, index) of host_list" :key="item.pk">
                    <td>{{ item.pk }}</td>
                    <td>{{ item.fields.package_version }}</td>
                    <td>{{ item.fields.md5_number }}</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        new Vue({
            el:"#get_host_data",
            data: {
                host_list: []
            },
            methods:{
                GetHostData:function(){
                    var url = "http://127.0.0.1:8001/super_cmdb/serverhost_list/";
                    axios.get(url).then(response => {
                        if (response.data.status==0) {
                            this.host_list = response.data.message;
                            console.log(response.data.message);
                            console.log("获取机器列表成功")
                    } else {
                            console.error("获取机器列表失败")
                        }
                    })
                }
            },
            mounted:function () {   //自动触发写入的函数
                this.GetHostData();
            }
        })
    </script>
    </body>
    </html>
  • 相关阅读:
    ural 1723 Sandro's Book
    ural 1104 Don’t Ask Woman about Her Age
    ural 1052 Rabbit Hunt
    ural 1837 Isenbaev's Number
    ural 1348 Goat in the Garden 2
    ural 1207 Median on the Plane
    ural 1640 Circle of Winter
    段错误 核心已转储尝试解决
    显卡相关命令介绍【转载】
    Linux的top命令学习【转载】
  • 原文地址:https://www.cnblogs.com/chenjw-note/p/13735410.html
Copyright © 2011-2022 走看看