生命週期函數以及vue的全局註冊

beforeCreate 在創造實例以前 created 創造實例之後 beforeMount 在掛載前 render 渲染節點到頁面上 //將虛擬dom數組渲染出來 mounted 掛載之後 beforeUpdate 修改以前 updated 修改之後 在這裏不要進行數據的持續修改相似 +=相似的操做會引發死循環 beforeDestory 銷燬以前 //用來釋放非vue引發的資源。如setInterval(); destroyed 銷燬以後 在組件激活 <keep-alive></keep-alive>時能夠調用的鉤子函數
activated 在組件卸載 <keep-alive></keep-alive>時調用的鉤子函數
deactivated 在watch中能夠深度監聽 wacth:{ //深度監聽是用來監聽

但只是淺監聽,只監聽數據第一層或者第二層,vue

何爲第二層?vue-router

let obj = {name: 'xx', child: {age: 11}};npm

 "obj.child.age":{ handler(newValue,OldValue)=>{ immediate:true, deep:true //深度監聽 } } }
var vm = new Vue({ data: { a: 1, b: 2, c: 3 }, watch: { a: function (val, oldVal) { console.log('new: %s, old: %s', val, oldVal) }, // 方法名
    b: 'someMethod', // 深度 watcher
 c: { handler: function (val, oldVal) { /* ... */ }, deep: true } } }) vm.a = 2 // -> new: 2, old: 1
Vue API 全局配置(Vue.config) silent 類型: Boolean 取消Vue全部的日誌和警告 Vue.config.silent = false
================= optionMergeStrategies 類型:Function 自定義合併策略的選項。 合併策略選項分別接受第一個參數做爲父實例,第二個參數爲子實例,Vue實例上下文被做爲第三個參數傳入。 Vue.config.optionMergeStrategies._my_option = function(parent, child, vm) { return child + 1 } const Profile = Vue.extend({ _my_option: 1 }) ================= Vue.directive(id, [definition]) 註冊或獲取全局指令。 // 註冊
Vue.directive('my-directive', { bind: function () {}, inserted: function () {}, update: function () {}, componentUpdated: function () {}, unbind: function () {} }) // 註冊(傳入一個簡單的指令函數)
Vue.directive('my-directive', function () { // 這裏將會被 `bind` 和 `update` 調用
}) // getter,返回已註冊的指令
var myDirective = Vue.directive('my-directive') 
後端路由:根據用戶的不一樣的請求返回不一樣的內容。 vue-router 是根據hash值實現的。 根據監聽hashchange事件。 npm i vue-router --save 1)import VueRouter from "vue-router"
2) Vue.use(VueRouter) 3) new VueRouter

 

相關文章
相關標籤/搜索