怎樣解決 [Vue warn]: The computed property "count" is already defined in data. 報錯問題?
最近在寫vue專案時候發現一個專案中報如下錯誤
vue.esm.js?5425:578 [Vue warn]: Property or method "counit" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See:
https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <App> at src\Vuex.vue
<Root>
程式碼如下:
store.js:
import Vue from 'vue'
import Vuex from 'vuex'//記得用cnpm install vuex --save
Vue.use(Vuex)
const state={//狀態物件
count:4
}
const mutations={//觸發狀態
jia(state){
state.count++;
},
jian(state){
state.count--;
}
}
export default new Vuex.Store({
state,
mutations
})
main.js註冊:
import Vue from 'vue'
import App from './App'
import router from './router'
import store from'./store'
import vuex from'./Vuex'
Vue.config.productionTip = false
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App },
store,
render:xx=>xx(vuex)
})
vuex.vue程式碼如下:
<template>
<div id="app">
<h1>Hello,World</h1>
<p>{{$store.state.count}}-{{count}} </p>
<button @click="$store.commit('jia')">+</button>
<button @click="$store.commit('jian')">-</button>
</div>
</template>
<script>
export default{
name:'app',
data(){
return {
count:0
}
},
computed:{
count(){
return this.$store.state.count
}
}
}
</script>
<style>
</style>
我當時搞了半天還是沒解決,後來我用有道翻譯了此句話The computed property "count" is already defined in data的意思:計算的屬性“count”已經在資料中定義。那麼照此推理,main.js和store.js沒有問題,後來我把計算屬性中computed中count改為counit並且把-{{count}}改為-{{counit}}問題解決。這說明計算屬性的名字不能與data中屬性同名。
相關文章
- [Vue warn]: The data property "dialogVisible" is already declared as a prop. Use prop default valueVue
- 安裝vue/cli報錯問題解決Vue
- vue專案報錯[Vue warn]: Property “visible“ must be accessed with “$data.visible“ because properties startVue
- 解決vue使用Sass時候的報錯問題Vue
- vue使用vue-amap元件報錯AMap is not definedVue元件
- 解決 Inkscape 報錯 Duplicate 問題
- 奇怪報錯資訊“db already exists with different case already have”解決方法
- Laravel 路由學習 - 遇到問題,報錯:Route [home] not definedLaravel路由
- vue scoped 解決樣式不生效問題Vue
- npm WARN unmet dependency錯誤解決方法NPM
- Python 解決 :NameError: name 'reload' is not defined 問題PythonError
- 解決proto3的"Timestamp" is not defined問題
- 解決eslint空格報錯等問題EsLint
- 設定autotrace的報錯問題解決
- 解決cookies儲存中文報錯問題Cookie
- 報錯No bean named ' is defined的原因和解決方案Bean
- [Vue warn]: Error in render: "TypeError: Cannot read property 'matched' of undefined" found in <App> at src/App.vueVueErrorUndefinedAPP
- 使用API28報錯問題及解決API
- jquery-weui微信支付報錯問題解決jQueryUI
- matplotlib中文報錯問題及解決方案
- mac 下PyCharm執行報錯問題解決MacPyCharm
- vue+echarts報錯Cannot read property ‘init‘ of underfinedVueEcharts
- VUE—刪除HelloWorld.vue後報錯 `--fix` option報錯的解決Vue
- jQuery報錯:Uncaught ReferenceError: $ is not definedjQueryError
- win10 儲存excel報錯 許可權問題怎麼解決Win10Excel
- [Laravel系列] 解決laravel中paginate()與distinct() count語句錯誤問題Laravel
- 【爬坑日記】vue中引入echarts,報錯ReferenceError: echarts is not definedVueEchartsError
- 解決MMM啟動監控報錯的問題
- vm安裝ubuntu後,update報錯問題解決Ubuntu
- 解決mysql_query()報錯的相關問題MySql
- 解決VUE引用element不能顯現元件css樣式問題Vue元件CSS
- 怎樣成為解決問題的高手?——關於問題解決的關鍵4步驟
- 【問題解決】property [elasticsearch.version] is missing for plugin [head]ElasticsearchPlugin
- vue3.0使用vue-seamless-scroll報錯問題Vue
- 請問這個報錯該怎麼解決,謝謝
- mongodb find報錯怎麼解決MongoDB
- vue報錯:[Vue warn]: Invalid prop: type check failed for prop "value". Expected Number, got String....VueAIGo
- Uncaught Error: Bootstrap‘s JavaScript requires jQuery報錯問題解決ErrorbootJavaScriptUIjQuery