将Vue-switch值绑定到数据prop

时间:2017-09-08 22:28:54

标签: javascript checkbox data-binding vue.js switch-statement

我正在使用vue-switch打开和关闭,我需要知道它处于什么状态。根据https://www.npmjs.com/package/vue-switch的文档我应该使用:value.sync =& #34;肘节"在交换机组件中有一个名为' toggle'的数据属性,我已经完成了。我收到以下错误:

ADJP

我的HTML:

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "value" vue switch found in ---> <Switcher> at E:\Dev\BackgroundCheck.Members\front-end\node_modules\vue-switch\switch.vue

我的JS:

<switcher size="lg" color="green" :value.sync="toggle"></switcher>

switch.vue代码:

<script>
import mySwitch from 'vue-switch';

export default {
  name: 'BackgroundReports',
  components: {
    'switcher': mySwitch
  },
  computed: {
    report() { return this.$store.getters.currentReport },
    isBeingMonitored() { return this.$store.getters.isBeingMonitored }
  },
  mounted() {
    this.toggle = this.isBeingMonitored;
  }
}
</script>

1 个答案:

答案 0 :(得分:2)

您会注意到包中实际上有两个组件。一个用于vue 1. *,一个用于vue 2. *。您只需要导入正确的。

# Form is sent
data = request.POST.copy()
data.update({'user': request.user.pk })
form = ImageCreateForm(data=data)
if form.is_valid():
    # Form data is valid
    new_item = form.save()
    messages.success(request, 'Image added successfully')
    # Redirect to the newly created item detail view
    return redirect(new_item.get_absolute_url())