text VUE.JS Deep Dive

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text VUE.JS Deep Dive相关的知识,希望对你有一定的参考价值。

<div id="count"></div>
<button onclick="state.count++">++</button>

<script>
let currentEffect

class Dep {
  constructor() {
    this.subscribers = new Set()
  }

  depend() {
    if (currentEffect) {
      this.subscribers.add(currentEffect)
    }
  }

  notify() {
    this.subscribers.forEach(sub => {
      sub()
    })
  }
}

function effect(runner) {
  currentEffect = runner
  runner()
  currentEffect = null
}

// ---

function observable(obj) {
  Object.keys(obj).forEach(key => {
    let value = obj[key]
    const dep = new Dep()

    Object.defineProperty(obj, key, {
      get() {
        dep.depend()
        return value
      },
      set(newValue) {
        value = newValue
        dep.notify()
      }
    })
  })

  return obj
}

const state = observable({
  count: 0
})

effect(() => {
  document.getElementById('count').textContent = state.count
})

state.count++
</script>
https://github.com/nuxt/nuxt.js/issues/2680
https://stackoverflow.com/questions/46805455/how-use-own-js-as-plugin-using-nuxt-js
http://vuejs-templates.github.io/webpack/

以上是关于text VUE.JS Deep Dive的主要内容,如果未能解决你的问题,请参考以下文章

《Docker Deep Dive》Note - Docker 引擎

Deep Dive 3 - NIO

APK Analyzer: An Android Tool Time Deep Dive

《Docker Deep Dive》Note - 纵观 Docker

Perl 6 Deep Dive

A Deep Dive into Rescalable State in Apache Flink