国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

如何確保輸入字段足夠?qū)捯酝暾@示內(nèi)容?
P粉014218124
P粉014218124 2023-09-02 22:36:56
0
2
717
<p>我正在使用一個包含許多列的表格中的 Vuetify 文本字段組件。可能該組件包含的內(nèi)容太多而無法顯示,并且從用戶體驗的角度來看,如果有許多單元格,通過在字段內(nèi)滾動來檢查內(nèi)容會花費太多時間。</p> <p>純 HTML 示例</p> <p>Vuetify 示例</p> <p>我的第一個想法(如果你有更好的想法,請告訴我)是顯示一個工具提示來顯示完整的內(nèi)容,但是如果組件能夠顯示完整的內(nèi)容,這樣做會很煩人。因此,我只想在內(nèi)容被隱藏/截斷時顯示工具提示。</p> <p>那么有沒有辦法知道組件是否顯示完整的內(nèi)容,或者是否有內(nèi)容被隱藏/截斷?(表格性能很重要,所以我不知道在值更改時進行非常復雜的計算是否值得)</p> <p>我嘗試了</p> <p>(游樂場)</p> <pre class="brush:php;toolbar:false;"><script setup> import { ref, watch } from 'vue' const field = ref() const msg = ref( 'Hello World! too much content in this text field component to display.' ) const isCuttingOff = ref(false) watch( msg, () => { const inputWidth = field.value?.clientWidth const inputValueWidth = msg.value.length // !!! measure the input value here !!! console.log({ inputWidth, inputValueWidth }) isCuttingOff.value = inputWidth < inputValueWidth }, { immediate: true } ) </script> <template> <v-app> <div class="text-h3">Is cutting off: {{ isCuttingOff }}</div> <v-container class="w-25"> <v-text-field ref="field" label="fsfdsf" v-model="msg" /> </v-container> </v-app> </template></pre> <p>但是</p> <ul> <li>在啟動時,變量<code>inputWidth</code>是未定義的</li> <li>我不知道如何計算變量<code>inputValueWidth</code></li> </ul></p>
P粉014218124
P粉014218124

全部回復(2)
P粉473363527

使用CSS來顯示文本的溢出,例如....(省略號),并使用title屬性在懸停時顯示完整內(nèi)容,類似彈出窗口

<script setup>
import { ref } from 'vue'

const msg = ref('Hello World! too much content in this text field component to display')
</script>

<template>
  <h1 :title=msg>{{ msg }}</h1>
  <input v-model="msg">
</template>

<style>
  h1{
    max-width: 15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>
P粉342101652

通過修改您的代碼,我成功地比較了文本框的clientWidthscrollWidth。

1- 消除了field引用。

2- 給v-text-field添加了一個id。

3- 添加了一個check函數(shù),并在watch回調(diào)函數(shù)中調(diào)用它。

4- 在check函數(shù)內(nèi)部,我檢查了輸入框的clientWidthscrollWidth。

5- 為了在初始加載時運行它,我將msg賦值為空字符串,并在腳本底部將其更改為原始字符串。

在此處查看:這里

<script setup>
  import { ref, watch } from 'vue'

  const msg = ref("")

  const isCuttingOff = ref(false)

  function check() {
    const elm = document.querySelector('#txt')
    isCuttingOff.value = elm.clientWidth < elm.scrollWidth;
    // todo : custom tooltip or any other solution for long texts
  }

  watch(
    msg,
    (currentMsg, oldMessage, callback) => {
      callback(check)
    },
    { immediate: true }
  )

  msg.value =
    'Hello World! too much content in this text cfield component to display.'
</script>
<script></script>
<template>
  <v-app>
    <div class="text-h3">Is cutting off: {{ isCuttingOff }}</div>
    <v-container class="w-25">
      <v-text-field id="txt" v-model="msg" />
    </v-container>
  </v-app>
</template>
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板