简体   繁体   English

Vue + Asp.Net MVC - 在 cshtml 属性中使用 vue mustache

[英]Vue + Asp.Net MVC - Using vue mustache in cshtml attributes

As we know from Vue's documentation we can use vue mustaches to acces properties also inside of html element's attributes正如我们从 Vue 的文档中了解到的,我们可以使用 vue mustaches 来访问 html 元素属性中的属性

But for some reason I can't make this work in .net's .cshtml pages但出于某种原因,我无法在 .net 的.cshtml页面中进行这项工作

heres simple example (for ui I am using Element-UI library):这是一个简单的例子(对于 ui,我使用的是 Element-UI 库):


<el-table :data="tableData"
      row-key="Id">
    <el-table-column prop="Price"
                     label="Standard">
        <template slot-scope="props">
            <span v-if="edit == false">{{ props.row.Price }}</span> @*this is working*@
            <div v-if="edit == true">
                <input id="price-{{ props.row.Id }}" type="text" v-model="props.row.Price">@*v-model works but id not*@
            </div>
        </template>
    </el-table-column>
</el-table>

Output in source code says that Id of input element is price-{{ props.row.Id }} , but should be for example price-1源代码中的输出表示输入元素的 Id 是price-{{ props.row.Id }} ,但应该是例如price-1

Do you have any suggestions for me?你对我有什么建议吗?

I think you are trying to bind row.id to textbox id attribute.我认为您正在尝试将 row.id 绑定到文本框 id 属性。 You should do it like below.你应该像下面那样做。

<input v-bind:id="props.row.Id" customeAttr="price" type="text" v-model="props.row.Price">

OR you can change your model data to have a get property which can return custom string like 'price-' + id.或者,您可以将模型数据更改为具有可以返回自定义字符串(如“price-”+ id)的 get 属性。

{
  id: 1,
  price: 10,
  get customId() {        
    return 'price-' + this.id;
  }      
}

Detailed Example详细示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM