2 回答

TA貢獻1893條經(jīng)驗 獲得超10個贊
你的例子對于描述二者不同這點上,沒有幫助。給你看這個例子:JSFiddle
<div id="app">
? <!-- 每次點擊時,顯示的時間都不同 -->
? <button @click="showMethod">methodsNow</button>
? <!-- 每次點擊時,顯示的時間都相同 -->
? <button @click="showComputed">computedNow</button>
</div>
new Vue({
? el: '#app',
? data: {
? ? message: 'Hello Vue.js!'
? },
? methods:{
? ? methodsNow: function(){
? ? ? return new Date().toLocaleString();
? ? },
? ? showMethod: function() {
? ? ? ? ?alert(this.methodsNow());
? ? },
? ? showComputed: function() {
? ? ? ? ?alert(this.computedNow);
? ? }
? },
? computed:{
? ? computedNow: function(){
? ? ? return new Date().toLocaleString();
? ? }
? }
})
添加回答
舉報