[Vue] Vue 옵션 톺아보기 - Global API

Goni·2022년 12월 13일
0

Vue

목록 보기
2/2

Vue.extend(options)

  • Vue base constructor의 sub class를 만든다.
  • args 에는 component option이 있어야 한다.



Vue.nextTick([callback, context])

  • DOM에서 모든 update 이후 실행되는 함수이다.
  • async/await 가능하다
    await nextTick(); 이후 실행되는 것들이 callback 함수들이라고 보면 된다.
// modify data
vm.msg = 'Hello'

// DOM not updated yet
Vue.nextTick(function () {
  // DOM updated
})

// usage as a promise (2.1.0+, see note below)
Vue.nextTick()
  .then(function () {
    // DOM updated
  })



Vue.set(target, propertyName/index, value)

  • reactive object에 새로운 요소를 설정한다.
  • update를 발생시킨다.
  • 새로 추가되는 것에만 반응한다.
    (기존 속성에 대한 변경은 추적하지 않음)
  • Vue가 객체 속성 추가를 감지하지 못하는 것을 방지할 수 있음



Vue.delete(target, propertyName/index)

  • 요소 삭제 후 update를 일으킨다.
  • Vue 객체가 속성 삭제를 감지하지 못하는 것을 방지할 수 있다.
  • 되도록이면 사용하지 않는 것이 좋다.



Vue.directive(id, [definition])

  • global directive를 등록한다.
// register
Vue.directive('my-directive', {
  bind: function () {},
  inserted: function () {},
  update: function () {},
  componentUpdated: function () {},
  unbind: function () {}
})

// register (function directive)
Vue.directive('my-directive', function () {
  // this will be called as `bind` and `update`
})

// getter, return the directive definition if registered
var myDirective = Vue.directive('my-directive')



Vue.filter(id, [definition])

  • global filter를 등록한다.
// register
Vue.filter('my-filter', function (value) {
  // return processed value
})

// getter, return the filter if registered
var myFilter = Vue.filter('my-filter')



Vue.component(id, [definition])

  • global component를 등록한다.



Vue.use(plugin)

  • Vue.js 플러그인을 설치한다.
  • plugin이 object인 경우 install 메소드를 호출해야 한다.
  • new Vue() 이전에 호출한다.
  • 특정 플러그인을 다중으로 호출 시 한번만 호출하도록 지원한다.
Vue.use(MyPlugin) -> MyPlugin.install(Vue)



Vue.mixin(mixin)

  • global mixin을 등록한다.
  • 생성된 모든 인스턴스에 영향을 준다.
  • 추천하지 않는다.



Vue.compile(target)

  • string template을 render 함수로 전환한다.
  • full build일 경우에만 사용 가능하다.



Vue.observable(object)

  • 객체를 반응형으로 만들어준다.
  • render함수 또는 computed 속성에서 접근 가능하다.
  • update trigger를 일으킨다.





참고문서
https://v2.vuejs.org/v2/api/#Global-API

0개의 댓글