【问题标题】:Why is v-model not showing up? Need to show value when in edit mode on form为什么 v-model 没有出现?在表单上处于编辑模式时需要显示值
【发布时间】:2018-01-19 09:20:32
【问题描述】:

嘿,我是一名前端开发人员,希望集成一些使用 vue JS 的后端数据,我对此很陌生。

我有一个表单,当用户单击“编辑”时,我正在显示相同的表单,但我希望填充这些值。

这里是相关的JS:

$(document).ready(function() {

    new Vue({
        el: 'body',

        data: { 

            editMode: false,


            challenge: null,

            challenges: <%= raw @campaign.challenges.to_json(include: [:challenge_tags, :challenge_filters], methods: [:has_link, :encoded_link, :is_active, :contact_count, :total_clicks, :default_image, :completions, :total_targeted, :total_contacts]) %>,
        },

        methods: {

           edit: function(challenge) {
            this.editMode = true;
            this.challenge = challenge; **
           }
        }
    })    
});

** 这是一个建议,但似乎没有用。

这里是 HTML:

<input class="input" type="text" placeholder="challenge name" v-model="challlenge.name">

例如,这可以正常工作:

<span v-if="editMode">Edit</span>

最好让它与 v-model 一起工作。

任何有用的建议!

编辑:当我添加 v-if="challenge.name" 时,该字段没有显示,这告诉我可能没有访问数据?

【问题讨论】:

  • 感谢@bert 重新格式化,你打败了我!

标签: javascript html forms templates vue.js


【解决方案1】:

如果您这样做v-if="challenges &amp;&amp; challenges.name",当challenge.name 中有可用数据时,将显示该字段

【讨论】:

  • 这似乎只是使输入字段仅在该数据可用时才出现。这是有帮助的,因为我看到该数据不可用......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-05
  • 1970-01-01
  • 2021-12-01
  • 2018-11-04
相关资源
最近更新 更多