-1

I have follow codes, which is a router component

const tag_cloud_links = {
  template:
  `
  <div class="tag-cloud-links">
    <router-link v-for="(value,key) in tags"
      :key="value.date"
      :to="{name:'tags',params: getBase(value)}">
      {{ key }}
    </router-link>
  </div>
  `
  ,
  computed: {
    getBase(value){
      return value.path.slice(6,value.path.length - 1)
    }
  },
  props:{
    tags:Object
  }
};

when I try debug getBase(value)

enter image description here

as you can see, value is a vue instance

when I go back stack to follow

enter image description here

value is correct object which is what I want to pass to getBase,

But why when vue call computed function, params change to vue instance?

When I change computed to methods

  methods: {
    getBase(value){
      return value.path.slice(6,value.path.length - 1)
    }
  },

enter image description here

value is corrent object, not is vue instance anymore

Why have difference params between computed and methods ?

0

1 Answer 1

1

I believe you can only set computed properties via getter/setter syntax. Otherwise, computed "methods"/properties should not have any arguments. They are served as quick reactive accessors and called without parentheses in a template, btw. In your case you clearly need to use method, and not a computed property. Read more about Vue's computed properties.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.