vue.js - 选择完成后,Vue Multiselect : How to send console. 记录

标签 vue.js vuejs2

使用Vue Multiselect ,一旦我做出选择,我就会尝试发送console.log。我以为把它放在 watch 里就可以了,但它不起作用。应该放在哪里。请参阅下面我的组件。

组件

<template>
  <div>
    <label v-for="topic in topics" class="radio-inline radio-thumbnail" style="background-image: url('http://s3.hubsrv.com/trendsideas.com/profiles/74046767539/photo/3941785781469144249_690x460.jpg')">
      <input type="radio" v-model="internalValue" name="topics_radio" :id="topic.id" :value="topic.name">
      <span class="white-color lg-text font-regular text-center text-capitalize">{{ topic.name }}</span>
    </label>
  </div>
</template>

<script>
export default {
  props: ['value'],
  data () {
    return {
      internalValue: this.value,
      topics: []
    }
  },
  mounted(){
    axios.get('/vuetopics').then(response => this.topics = response.data);
  },
  watch: {
    internalValue(v){
      this.$emit('input', v);
      console.log('topic has been chosen!!!');
    }
  }
}
</script>

最佳答案

它火了events ,这样你就可以捕获他们。

<multiselect ... @select="doSomething" ...>

然后添加您的方法

...
methods: {
    doSomething(selectedOption, id) {
        console.log(selectedOption);
    }
}

确保您正确实现了 vue-multiselect,我在您的代码中没有看到该组件。

关于vue.js - 选择完成后,Vue Multiselect : How to send console. 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42776830/

相关文章:

css - Vue JS v-for 生成的组件不延伸座高(overflow-y)

javascript - Vuejs DOM 未更新

javascript - Vue Chart.js - 无法使用图表数据集的返回数据

javascript - Prerender vue.js 2.0组件(类似于vue 1中的this.$compile)

vue.js - nextTick 是什么,它在 Vue.js 中有什么作用?

html - 删除 Vue 中 html 和 body 元素的边距和填充?

javascript - Vuex 中的 Action 完成后从商店调用组件函数

vuejs2 - $router.push 不工作?

javascript - Vue.js 如何在单击父下拉按钮后在组件中启动 axios.get?

javascript - axios get 函数在 get 方法中参数为 null 或为空时会导致 404 错误