vue.js - 如何在渲染函数中实现 `v-model`?

标签 vue.js

当我读取渲染函数的数据时:https://v2.vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth

没有v-model的地方,v-model在Vue.js 2.0中不存在。

下面是官网给的数据例子,但是没有说v-model放置:

{
  // Same API as `v-bind:class`
  class: {
    foo: true,
    bar: false
  },
  // Same API as `v-bind:style`
  style: {
    color: 'red',
    fontSize: '14px'
  },
  // Normal HTML attributes
  attrs: {
    id: 'foo'
  },
  // Component props
  props: {
    myProp: 'bar'
  },
  // DOM properties
  domProps: {
    innerHTML: 'baz'
  },
  // Event handlers are nested under `on`, though
  // modifiers such as in `v-on:keyup.enter` are not
  // supported. You'll have to manually check the
  // keyCode in the handler instead.
  on: {
    click: this.clickHandler
  },
  // For components only. Allows you to listen to
  // native events, rather than events emitted from
  // the component using `vm.$emit`.
  nativeOn: {
    click: this.nativeClickHandler
  },
  // Custom directives. Note that the `binding`'s
  // `oldValue` cannot be set, as Vue keeps track
  // of it for you.
  directives: [
    {
      name: 'my-custom-directive',
      value: '2',
      expression: '1 + 1',
      arg: 'foo',
      modifiers: {
        bar: true
      }
    }
  ],
  // Scoped slots in the form of
  // { name: props => VNode | Array<VNode> }
  scopedSlots: {
    default: props => createElement('span', props.text)
  },
  // The name of the slot, if this component is the
  // child of another component
  slot: 'name-of-slot',
  // Other special top-level properties
  key: 'myKey',
  ref: 'myRef'
}

你看有很多key,比如refkeyprops等等,我怎么实现这个需求?

最佳答案

props: {
    myProp: 'bar',
    value: 'someValue'
  },
  on: {
    click: this.clickHandler,
    input: function(value) {
        // change someValue here using value
    },

  },

关于vue.js - 如何在渲染函数中实现 `v-model`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49810784/

相关文章:

javascript - 如何在没有 console.log 的情况下登录 Vue.js?

javascript - Axios 弃用并发请求?

javascript - 如何将字符串附加到 Vue 模板中的常量?

html - 需要增加 b 模态宽度。 VueJS.Bootstrap

vue.js - Vue3/Inertia 无法解析组件

javascript - 你如何在 nuxt 3 上获得很棒的字体设置

javascript - 如何使用 `&lt;script setup>` ?

javascript - 范围内的冲突组件

javascript - Vue.js - 更新的数组项值不会在页面中更新

javascript - 使用 Quasar-Framework 0.15 进行 Jest 单元测试配置