{{ count }} {{ double }}
export default {
data: function() { return { count: 0 } },
computed: {
double: function() {
return this.count * 2
}
},
methods: {
plus: function() {
this.count++
}
}
}
{{ count }} {{ double }}
import Vue from 'vue'
export default class App extends Vue {
count = 0
get double() {
return this.count * 2
}
plus() {
this.count++
}
}
{{ state.count }} {{ state.double }}
import { reactive, computed } from 'vue'
export default {
setup() {
const state = reactive({
count: 0,
double: computed(() => state.count * 2)
})
function plus() {
state.count++
}
return { state, plus }
}
}
Object-base
Class-base
Composition