Method “computed“ has type “object“ in the component definition. Did you reference the function corr

今天写vue登录页面时遇到了Bug,找了很久发现将computed写到了methods里面,应该是在methods外面

报错:
Method “computed“ has type “object“ in the component definition. Did you reference the function corr
修改前:

<script>
import { mapGetters } from 'vuex'
export default {
  name: "WelcomeLogin",
  methods: {
    gotoLogin() {
      this.$router.replace('/login')
    },
    gotoRegister() {
      this.$router.replace('/register')
    },
  computed: {
    ...mapGetters([
      'token'
    ])
  }
  },

};
</script>

修改后:

<script>
import { mapGetters } from 'vuex'
export default {
  name: "WelcomeLogin",
  methods: {
    gotoLogin() {
      this.$router.replace('/login')
    },
    gotoRegister() {
      this.$router.replace('/register')
    },
  },
  computed: {
    ...mapGetters([
      'token'
    ])
  }
};
</script>

上一篇:v-for遍历


下一篇:computed计算属性