gpt4 book ai didi

javascript - table 上的 Vue.js v 组件

转载 作者:搜寻专家 更新时间:2023-10-30 22:53:02 24 4
gpt4 key购买 nike

在 Vue.js 文档中,他们说在表格中使用组件时必须使用 v-component 而不是直接的 component-tag。但这不起作用:您是否有任何解决方法 - 即使使用 CSS 格式 - 或修复?

@extends('app')

@section('content')
<div class="table-responsive" id="vueTable">
<table class="table-striped">
<thead>
<td class="table-cell"><strong>Aktion</strong></td>
</thead>
<tr v-component="members" class="success" v-repeat="members" inline-template>
<td>@{{ $data | json }}</td>
</tr>
</table>
</div>
@endsection

@section('footer')
<script src="/js/vue.js"></script>
<script>
var v = new Vue({
el: '#vueTable',
data: {
members: [{
prename: 'Deniz',
lastname: 'Adanc'
}]
},
components: {
members: {
template: ''
}
}
});
</script>
@endsection

最佳答案

Evan 再次在 1.0 中进行了重大更改。在多次失败的尝试之后,这是 html/javascript 的组合,在我尝试将自定义组件包含在表中(这又是另一个父组件)时对我有用:

HTML 文件:

    <script id="comments-template" type="text/x-template">    
<table>
<tbody>
<tr is="my-comment" :data="comment" v-for="comment in comments">
</tr>
</tbody>
</table>
</script>

<script id="comment-template" type="text/x-template">
<tr>
<td>{{comment}}</td>
</tr>
</script>

JavaScript 片段:

    Vue.component('my-comment', {
template: '#comment-template',
props: [
'data',
],
data: function() {
return {
comment: '',
};
},
ready: function() {
this.comment = this.data.comment;
}
...
});

Vue.component('my-comments', {
template: '#comments-template'
...
});

这里有两个组件:my-comments(这是一个表格)和my-comment(这是表格中的一行/几行)。 v-for 循环中的 comment 作为 data 属性传递,并在 my-comment 中重新映射到实际数据我的评论 (this.comment = this.data.comment)。

它看起来相当丑陋而且不完全直观,但至少它有效。

关于javascript - table 上的 Vue.js v 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31244617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com