-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assigning to a computed property without setter does not fail #6078
Comments
@yyx990803 I couldn't find codes like this: // store.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
isLoading: false
}
const mutations = {
updateLoadingStatus (state, payload) {
state.isLoading = payload.isLoading
}
}
export default new Vuex.Store({
state,
mutations
}) // App.vue
<template>
<div id="app">
<router-view></router-view>
<loading v-model="isLoading"></loading>
</div>
</template>
<script>
import { Loading } from 'vux'
import { mapState } from 'vuex'
export default {
name: 'app',
components: {
Loading
},
computed: {
...mapState({
isLoading: state => state.isLoading
})
}
}
}
</script> |
@Plortinus That happens because of the |
Thanks a lot.I tried to use the But I am wondering if my solution is a good practice or not.The purpose of these codes is to show a loading toast when switch one page to another page in an SPA. <template>
<div id="app">
<router-view></router-view>
<loading :value.sync="isLoading"></loading>
</div>
</template>
<script>
import { Loading } from 'vux'
import { mapState } from 'vuex'
export default {
name: 'app',
components: {
Loading
},
computed: {
...mapState({
isLoading: state => state.isLoading
})
}
}
</script> |
Why/when would the So I don't see a need for .sync or v-model or anything like it. |
I update the value of router.beforeEach(function (to, from, next) {
store.commit('updateLoadingStatus', { isLoading: true })
next()
})
router.afterEach(function (to) {
store.commit('updateLoadingStatus', { isLoading: false })
}) |
Yeah sure, but then that value will go from your parent component down to the Maybe you have a missunderstanding how props work, at least in combination with computed properties? |
okay mate this is a snippet of my code maybe it may help you figure out where you are wrong but i Think it should be easier now since i also had the same error but with getter `computed: { watch: { |
What problem does this feature solve?
If I have a computed property with only getter, setter is set to a noop. If I then try to assign to such a computed property, nothing happens. This can hide programming errors.
What does the proposed API look like?
I would suggest that when not in production, instead of a noop a warning function would be assigned to a setter and a warning message would be printed if one tries to assign a value to such computer property.
Alternatively, output of computed property without setter could be configured without a setter at all, as a read-only property.
The text was updated successfully, but these errors were encountered: