技术贴

搜索

vue 属性 传入 变量 动态属性

[复制链接]
查看: 1419   回复: 0
发表于 2021-7-6 11:27:59 | 显示全部楼层 |阅读模式
本帖最后由 搬砖人 于 2021-7-6 12:06 编辑

Dynamic Arguments

  1. <component
  2.     :[getConfigType()]="getConfigValue"
  3.     :api="formData[scope.$index][cindex]['api']"
  4.     :key="updatekey"
  5.     :placeholder="formData[scope.$index][cindex].placeholder"
  6.     :is="head.tag"
  7.     :elData="head"
  8.     :disabled="formData[scope.$index][cindex].formOperates == G.FORM_OPERATE.READ ? true : false"
  9.     v-model="formData[scope.$index][cindex].value"
  10.     v-bind="getConfById(head.formId)"
  11.     @change="getCustomConfig({
  12.     row:scope.$index,
  13.         cIndex: cindex,
  14.             tag: head.tag,
  15.                 type:G.CUSTOM_CONFIG.EVENT,
  16.                     eventFrom:G.EVENT_FROM.CHANGE
  17.     })"
  18. >
  19.         
  20.         
  21.         methods: {
  22.             //用一个方法来生成属性值
  23.             getConfigValue() {
  24.             },
  25.                 //用一个方法来生成一个属性名
  26.                 getConfigType() {
  27.                     alert()
  28.                     return 'test'
  29.                 },
复制代码


New in 2.6.0+

Starting in version 2.6.0, it is also possible to use a JavaScript expression in a directive argument by wrapping it with square brackets:

<!--
Note that there are some constraints to the argument expression, as explained
in the "Dynamic Argument Expression Constraints" section below.
-->

<a v-bind:[attributeName]="url"> ... </a>

Similarly, you can use dynamic arguments to bind a handler to a dynamic event name:

<a v-on:[eventName]="doSomething"> ... </a>

<a v-bind:['foo' + bar]="value"> ... </a>

<form v-on:submit.prevent="onSubmit"> ... </form>


参考:
https://vuejs.org/v2/guide/syntax.html



如果是传入多个动态属性

参考:

https://stackoverflow.com/questi ... l-parameters-in-vue

let data = {
  param1: 'val1',
  param2: 'val2',
  param3: 'val3'
}
<div v-bind="data"></div>
回复

使用道具 举报

您需要登录后才可以回帖   登录 立即注册

高级模式

搬砖人

楼主

技术交流博客

手机版|www.37talk.com ( 粤ICP备20020713号 )