Vue 命令

1、脚手架Cil搭建

全局安装 npm: npm install -g vue-cli

创建项目:vue init webpack vueapp(项目名称)

下载路由模块: npm install vue-router --save  (vue-router为路由名称)

安装http : npm install vue-resource --save

安装json-server:npm install -g json-server

https://github.com/typicode/json-server(json-server   官网)

2.http请求

export default {
        name: "customers",
        data() {
            return {
                customers: []
            }
        },
        methods: {
            fetchCustomers() {
                this.$http.get("http://localhost:3000/users")
                    .then(function (response){
                        this.customers = response.body
                    })
            }
        },
        created() {
            this.fetchCustomers()
        }
    }

 3、钩子函数

beforeCreate: function() {
    alert("组件实例化之前执行的函数");
},
created: function() {
    alert("组件实例化之完毕但页面还未显示");
},
beforeMount: function() {
    alert("组件挂在前,页面扔未展示,但虚拟DOM已经配置");
},
mounted: function() {
    alert("组件挂在后,此方法执行后,页面显示");
},
beforeUpdate: function() {
    alert("组件更新前,页面扔未更新,但虚拟DOM已经配置");
},
updated: function() {
    alert("组件更新后,此方法执行后,页面显示");
},
beforeDestory: function() {
    alert("组件销毁前");
},
destory: function() {
    alert("组件销毁");
}
原文地址:https://www.cnblogs.com/hhj3645/p/9488645.html