“v-data-table”现在在Vue3和Vite中显示数据或标题。

huangapple go评论65阅读模式
英文:

v-data-table now displaying data or headers in Vue3 and Vite

问题

我明白了,这是您的Vue项目代码的一部分,您想要翻译其中的注释和文字内容。以下是翻译后的内容:

<div v-if="marketdata.asks">
  <div>
    <v-layout>
      <v-flex md lg>
        <v-card-title>卖单</v-card-title>
        <v-data-table
          dense
          :sort-by="['price']"
          :sort-desc="[true]"
          disable-pagination
          hide-default-footer
          :headers="asksHeaders"
          :items="marketdata.asks"
          :items-per-page="5"
        >
          <template v-slot:header.price="{ header }">
            <!-- {{ header.text.toUpperCase() }} -->
            价格 ({{ wallets.rel.ticker }})
          </template>

          <template v-slot:header.maxvolume="{ header }">
            <!-- {{ header.text.toUpperCase() }} -->
            数量 ({{ wallets.base.ticker }})
          </template>

          <template v-slot:header.relamount="{ header }">
            <!-- {{ header.text.toUpperCase() }} -->
            总额 ({{ wallets.rel.ticker }})
          </template>

          <!--  https://www.jacklmoore.com/notes/rounding-in-javascript/ 进行四舍五入 -->
          <!-- 更好的方法是将其移到计算函数以提高可维护性和减少重复性 -->
          <template v-slot:item.price="{ item }"> {{ Number(Math.round(item.price+'e8')+'e-8') }}</template>

          <!-- 用于突出显示我的订单TODO在在AppTraderview中按价格分组之前需要一个price:uuid数组 -->
          <template v-slot:item.price2="{ item }">
            {{ Number(Math.round(item.price+'e8')+'e-8') }}
            <!-- 更好的实现在加载订单时由父组件处理然后承诺设置标志 -->
            <!-- <v-chip v-if="hasMyOrder(item.price)" color="purple" dark>我</v-chip> -->
            <v-chip v-if="item.myOrder" x-small color="purple" dark>*</v-chip>
          </template>

          <template v-slot:item.maxvolume="{ item }">{{ Number(Math.round(item.maxvolume+'e8')+'e-8') }}</template>
          <template v-slot:item.relamount="{ item }">{{ Number(Math.round(item.price*item.maxvolume+'e8')+'e-8') }}</template>
        </v-data-table>
      </v-flex>
    </v-layout>
  </div>
</div>

这是您代码中的部分内容的翻译。如果您需要更多翻译,请随时提出。

英文:

I am porting an old vue2 project to vue3 running on vite and using vuetify. I am trying to display my data table with values but it does not even show headers that supposedly static and defined in my script section.

&lt;div v-if=&quot;marketdata.asks&quot;&gt;
&lt;div&gt;
&lt;v-layout&gt;
&lt;v-flex md lg&gt;
&lt;v-card-title&gt;Asks&lt;/v-card-title&gt;
&lt;v-data-table
dense
:sort-by=&quot;[&#39;price&#39;]&quot;
:sort-desc=&quot;[true]&quot;
disable-pagination
hide-default-footer
:headers=&quot;asksHeaders&quot;
:items=&quot;marketdata.asks&quot;
:items-per-page=&quot;5&quot;
&gt;
&lt;template v-slot:header.price=&quot;{ header }&quot;&gt;
&lt;!-- {{ header.text.toUpperCase() }} --&gt;
Price ({{wallets.rel.ticker }})
&lt;/template&gt;
&lt;template v-slot:header.maxvolume=&quot;{ header }&quot;&gt;
&lt;!-- {{ header.text.toUpperCase() }} --&gt;
Amount ({{wallets.base.ticker }})
&lt;/template&gt;
&lt;template v-slot:header.relamount=&quot;{ header }&quot;&gt;
&lt;!-- {{ header.text.toUpperCase() }} --&gt;
Total ({{wallets.rel.ticker }})
&lt;/template&gt;
&lt;!-- Rounding from https://www.jacklmoore.com/notes/rounding-in-javascript/ --&gt;
&lt;!-- Better to move to computed function for maintainability/non-repetitive --&gt;
&lt;template v-slot:item.price=&quot;{ item }&quot;&gt; {{ Number(Math.round(item.price+&#39;e8&#39;)+&#39;e-8&#39;) }}&lt;/template&gt;
&lt;!-- For highlighting my orders, TODO need a price:uuid array before grouping by price in AppTraderview   --&gt;
&lt;template v-slot:item.price2=&quot;{ item }&quot;&gt;
{{ Number(Math.round(item.price+&#39;e8&#39;)+&#39;e-8&#39;) }}
&lt;!--
better implementation handled in parent component on load of orders, then promise to set flag
&lt;v-chip v-if=&quot;hasMyOrder(item.price)&quot; color=&quot;purple&quot; dark&gt;me&lt;/v-chip&gt;
--&gt;
&lt;v-chip v-if=&quot;item.myOrder&quot; x-small color=&quot;purple&quot; dark&gt;*&lt;/v-chip&gt;
&lt;/template&gt; 
&lt;template
v-slot:item.maxvolume=&quot;{ item }&quot;
&gt;{{ Number(Math.round(item.maxvolume+&#39;e8&#39;)+&#39;e-8&#39;) }}&lt;/template&gt;
&lt;template
v-slot:item.relamount=&quot;{ item }&quot;
&gt;{{ Number(Math.round(item.price*item.maxvolume+&#39;e8&#39;)+&#39;e-8&#39;) }}&lt;/template&gt;
&lt;/v-data-table&gt;

This is my script section with my headers defined, This is only part of my code both above and below

export default {
name: &quot;MarketData&quot;,
props: [&#39;wallets&#39;, &#39;marketdata&#39;, &#39;myOrdersThisMarket&#39;],
data: function() {
return {
cexprice: &quot;&quot;,
myOrders: &quot;&quot;,
takerDialog: false,
makerDialog: false,
activeCoins: [],
walletBalance: { base: 0, rel: 0 },
trade: { base: &quot;&quot;, rel: &quot;&quot;, price: &quot;&quot;, amount: &quot;0&quot; },
appName: &quot;MarketData&quot;,
customerrors: [],
asksHeaders: [
{
text: &quot;Price (rel)&quot;,
align: &quot;left&quot;,
sortable: true,
value: &quot;price&quot;
},
{ text: &quot;Amount (base)&quot;, align: &quot;left&quot;, value: &quot;maxvolume&quot; },
{ text: &quot;Total (rel))&quot;, align: &quot;right&quot;, value: &quot;relamount&quot; }
],
bidsHeaders: [
{
text: &quot;Price (rel)&quot;,
align: &quot;left&quot;,
sortable: true,
value: &quot;price&quot;
},
{ text: &quot;Base Amount&quot;, align: &quot;left&quot;, value: &quot;baseamount&quot; },
{ text: &quot;Can Cancel&quot;, align: &quot;right&quot;, value: &quot;maxvolume&quot; }
]
}
},

答案1

得分: 2

谢谢提供链接,现在我明白了问题。似乎有两个问题:

  • 你在text属性中设置了列标题,但在Vuetify 3中,这已经更改为title
  • 同样,header.&lt;column name&gt;插槽已被重命名为column.&lt;column name&gt;,所以v-slot:header.price现在应该是v-slot:column.price

如果你更新这些名称,应该可以正常工作。

英文:

Thank you for the link, now I understand the issue. Seems to be two things:

  • You are setting the column header title in the text property, but in Vuetify 3, that was changed to title.
  • Similarly, the header.&lt;column name&gt; slots were renamed to column.&lt;column name&gt;, so v-slot:header.price now is v-slot:column.price

If you update the names, it should work again.

huangapple
  • 本文由 发表于 2023年6月12日 07:53:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定