新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
[譯]Vue2.0的變化(一)之基本API變化
高層級(jí)的變化

- 模板解析器不再依賴于DOM(除非你使用真正的DOM作為模板),因此只要你使用字符串模板,你將不再受到任何1.0版本中的解析限制。但是,如果你依賴在存在的內(nèi)容中掛載一個(gè)元素作為模板(使用el元素),你將依然受到這些限制。
- 編譯器(將字符串模板轉(zhuǎn)換為渲染方法的部分)和運(yùn)行時(shí)間現(xiàn)在能夠被分開(kāi)。這里有兩種不同的構(gòu)建:
- 獨(dú)立構(gòu)建:包括編譯并且運(yùn)行。這種方式和vue 1.0幾乎完全一樣。
- 運(yùn)行時(shí)編譯:由于它不包括編譯器,在編譯步驟時(shí)要么預(yù)編譯模板,要么手動(dòng)編寫(xiě)渲染功能。npm包默認(rèn)導(dǎo)出這個(gè)版本,那么你需要有一個(gè)編譯的過(guò)程(使用Browserify或Webpack ),從中vueify或vue-loader將可以進(jìn)行模板預(yù)編譯。
全局配置
- Vue.config.silent
- Vue.config.optionMergeStrategies
- Vue.config.devtools
- Vue.config.errorHandler(新API,全局的掛鉤用于在組件渲染和監(jiān)控的時(shí)候處理未捕獲的錯(cuò)誤)
- Vue.config.keyCodes(新API,為v-on配置自定義的key的別名)
-
(已丟棄)
Vue.config.debug
-
(已丟棄)
Vue.config.async
-
(已丟棄)
Vue.config.delimiters
-
(已丟棄,使用v-html)
Vue.config.unsafeDelimiters
全局API
- Vue.extend
- Vue.nextTick
- Vue.set
- Vue.delete
- Vue.directive
- Vue.component
- Vue.use
- Vue.mixin
- Vue.compile(新API,只能用于獨(dú)立版本構(gòu)建)
- Vue.transition
-
(已丟棄,在el上設(shè)置
stagger
- Vue.filter
-
(已丟棄,使用組件)
Vue.elementDirective
-
(已丟棄,使用功能組件)
Vue.partial
選項(xiàng)
data
- data
- props
。prop
。default
。
(已丟棄,如果你需要轉(zhuǎn)換prop,請(qǐng)使用compute屬性)
coerce
。
(已丟棄,v-model在組件上可以工作
prop binding modes
- propsData(新API)只能用于實(shí)例
- computed
- methods
- watch
DOM
- el
- template
- render(新API)
-
(已丟棄,組件現(xiàn)在必須有一個(gè)根元素)
replace
生命周期鉤子
-
(已丟棄,請(qǐng)使用beforeCreate)
init
- created
- beforeDestroy
- destroyed
- beforeMount(新API)
- mounted(新API)
- beforeUpdate(新API)
- updated(新API)
- activated(新API,用于keep-alive)
- deactivated(新API用于keep-alive)
-
(已丟棄,使用mounted)
ready
-
(已丟棄,遷移到vue-router)
activate
-
(已丟棄,使用created)
beforeCompile
-
(已丟棄,使用mounted)
compiled
-
(已丟棄)
attached
-
(已丟棄,同上)
detached
Assets
- directives
- components
- transitions
- filters
-
(已丟棄)
partials
-
(已丟棄)
elementDirectives
雜項(xiàng)
- parent
- mixins
- name
- extends
- delimiters(新API,替代原版的全局配置選項(xiàng),只在獨(dú)立構(gòu)建中可用)
- functional(新API)
-
(已丟棄)
events
實(shí)例方法
data
- vm.$watch
-
(已丟棄,直接檢索值)
vm.$get
-
(已丟棄,使用Vue.set)
vm.$set
-
(已丟棄,使用Vue.delete)
vm.$delete
-
(已丟棄,沒(méi)有真正的使用)
vm.$eval
-
(已丟棄,同上)
vm.$interpolate
-
(已丟棄,使用devtools)
vm.$log
events
- vm.$on
- vm.$once
- vm.$off
- vm.$emit
-
(已丟棄,使用全局的事件或使用vuex,見(jiàn)下面)
vm.$dispatch
-
(已丟棄,同上)
vm.$broadcast
DOM
- vm.$nextTick
-
(已丟棄,在 vm.$el上使用本地API)
vm.$appendTo
-
(已丟棄)
vm.$before
-
(已丟棄)
vm.$after
-
(已丟棄)
vm.$remove
生命周期
- vm.$mount
- vm.$destroy
指令
- v-text
- v-html(注意{{{ }}} 被丟棄)
- v-if
- v-show
- v-else
- v-for
。key (替代 track-by)
。object v-for
。range v-for
。參數(shù)順序更新:數(shù)組中使用(value, index) in arr,對(duì)象中使用(value, key, index) in obj
。$index和$key被丟棄
- v-on
。modifiers
。on child component
。自定義鍵碼,目前版本Vue.config.keyCodes代替原來(lái)的Vue.directive('on').keyCodes
- v-bind
。作為prop
。xlink
。綁定對(duì)象
- v-bind:style
- prefix sniffing
- v-bind:class
- v-model
- lazy (as modifier)
- number (as modifier)
- ignoring composition events
-
(已丟棄,使用v-on:input)
debounce
- v-cloak
- v-pre
- v-once(新API)
-
(已丟棄,現(xiàn)在只是一個(gè)特殊的屬性ref)
v-ref
- v-el(和ref合并)
特殊組件
- :is
- async組件
- inline-template
-
(已丟棄)
partial
特殊屬性
- key
- ref
- slot
服務(wù)器端渲染
- renderToString
- renderToStream
- client-side hydration
當(dāng)前標(biāo)題:[譯]Vue2.0的變化(一)之基本API變化
轉(zhuǎn)載來(lái)源:http://m.fisionsoft.com.cn/article/djjhoop.html


咨詢
建站咨詢
