如何在另一个组件数据中使用Vue总线数据?

时间:2017-04-20 22:27:37

标签: vue.js vuejs2 vue-component

我有2个兄弟Vue组件,我通过总线向根发送他们的数据。但我不知道如何在组件中使用该总线数据。

以下是根目录中捕获的总线数据。

bus.$on("send-topic", selectedTopic => this.selectedTopic = selectedTopic);

如何在下面的示例中使用它来替换topic_id。这也是一个对象,所以我需要深入到ID属性。像selectedTopic['id']

这样的东西

组件示例

<script>
  import Multiselect from 'vue-multiselect'
  export default {
    components: { Multiselect },
    props: ['value', 'api-url', 'api-token'],
    data () {
      return {
        internalValue: this.value,
        options: []
      }
    },
    mounted(){
      axios.get( this.apiUrl + '/questions/businesses', {
          params: { 
            topic_id: 1, // This is where I need to use it //
            keywords: ['kitchen', 'paint'] 
          }, 
          headers: {
            'api-token': this.apiToken 
          }
        }).then(response => this.options = response.data);
      }
</script>

0 个答案:

没有答案
相关问题