v-slider (Vuetify)为什么没有宽度?

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

Why v-slider (Vuetify) has no width?

问题

只有默认的空v-slider标记没有宽度或拇指居中对齐:

v-slider (Vuetify)为什么没有宽度?

这个粗点是滑块的拇指,没有滑块条。

<div v-if="typeList[0] === 'grade'" class="formItem__grade">
    <v-radio-group v-model="item.value" inline>
         <v-radio v-for="el in item.meta.answers" :label="el" :value="el" :disabled="disable"></v-radio>
    </v-radio-group>
    <!-- 
    <v-slider v-model:model-value="item.value"
        :ticks="item.meta.answers"
        :max="item.meta.answers.length"
        show-ticks="always"
        step="1"
        tick-size="3"
    ></v-slider>
    -->
    <v-slider></v-slider>
</div>

在已注释的代码中,您可以看到我尝试设置属性,但没有成功。因此,我尝试了没有任何属性的<v-slider>(如图像中所示),但也不起作用。

英文:

I want to create a v-slider, but just on default empty v-slider tag has no width or thumb align center:

v-slider (Vuetify)为什么没有宽度?

This bold point is the thumb of slider and no one slider bar.

&lt;div v-if=&quot;typeList[0] === &#39;grade&#39;&quot; class=&quot;formItem__grade&quot;&gt;
    &lt;v-radio-group v-model=&quot;item.value&quot; inline&gt;
         &lt;v-radio v-for=&quot;el in item.meta.answers&quot; :label=&quot;el&quot; :value=&quot;el&quot; :disabled=&quot;disable&quot;&gt;&lt;/v-radio&gt;
    &lt;/v-radio-group&gt;
    &lt;!-- 
    &lt;v-slider v-model:model-value=&quot;item.value&quot;
        :ticks=&quot;item.meta.answers&quot;
        :max=&quot;item.meta.answers.length&quot;
        show-ticks=&quot;always&quot;
        step=&quot;1&quot;
        tick-size=&quot;3&quot;
    &gt;&lt;/v-slider&gt;
    --&gt;
    &lt;v-slider&gt;&lt;/v-slider&gt;
&lt;/div&gt;

In the commented code, you can see that I tried to set props, but it did not work. So I tried &lt;v-slider&gt; without any props (as in the image), but it does not work either.

答案1

得分: 0

这是您要翻译的代码部分,不要有别的内容:

"That happens when you don't wrap your Vuetify components into a v-app. It works when you do:

const { createApp, ref } = Vue;
const { createVuetify} = Vuetify;

const vuetify = createVuetify();
const App = {
  setup() {
    return {
      sliderVal1: ref(25),
      sliderVal2: ref(1), 
      item: {meta: {
        answers: [&#39;a1&#39;, &#39;a2&#39;]
      }},
      isVapp: ref(true)
    };
  }
};

const app = createApp(App);
app.use(vuetify).mount('#app');
<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.css\" />
<div id=\"app\">

  <label><input type=\"checkbox\" v-model=\"isVapp\"/> with v-app</label>
  
  <component :is=\"isVapp ? 'VApp' : 'div'\">
    <div>
      <v-slider v-model=\"sliderVal1\" />
    </div>
    {{sliderVal1}}
    <div>
      <v-slider
        v-model=\"sliderVal2\" 
        :ticks=\"Object.fromEntries(Object.entries(item.meta.answers))\" 
        :max=\"item.meta.answers.length - 1\" 
        show-ticks=\"always\" 
        step=\"1\" 
        tick-size=\"3\" 
        color=\"blue\"
      />
    </div>

    {{sliderVal2}}
    
  </component>
</div>
<script src=\"https://unpkg.com/vue@3/dist/vue.global.prod.js\"></script>
<script src=\"https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.js\"></script>

请注意,这是代码的翻译部分。

英文:

That happens when you don't wrap you Vuetify components into a v-app. It works when you do:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

const { createApp, ref } = Vue;
const { createVuetify} = Vuetify

const vuetify = createVuetify()
const App = {
  setup() {
    return {
      sliderVal1: ref(25),
      sliderVal2: ref(1), 
      item: {meta: {
        answers: [&#39;a1&#39;, &#39;a2&#39;]
      }},
      isVapp: ref(true)
    }
  }
}

const app = createApp(App)
app.use(vuetify).mount(&#39;#app&#39;)

<!-- language: lang-html -->

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.css&quot; /&gt;
&lt;div id=&quot;app&quot;&gt;

  &lt;label&gt;&lt;input type=&quot;checkbox&quot; v-model=&quot;isVapp&quot;/&gt; with v-app&lt;/label&gt;
  
  &lt;component :is=&quot;isVapp ? &#39;VApp&#39; : &#39;div&#39;&quot;&gt;
    &lt;div&gt;
      &lt;v-slider v-model=&quot;sliderVal1&quot; /&gt;
    &lt;/div&gt;
    {{sliderVal1}}
    &lt;div&gt;
      &lt;v-slider
        v-model=&quot;sliderVal2&quot; 
        :ticks=&quot;Object.fromEntries(Object.entries(item.meta.answers))&quot; 
        :max=&quot;item.meta.answers.length - 1&quot; 
        show-ticks=&quot;always&quot; 
        step=&quot;1&quot; 
        tick-size=&quot;3&quot; 
        color=&quot;blue&quot;
      /&gt;
    &lt;/div&gt;

    {{sliderVal2}}
    
  &lt;/component&gt;
&lt;/div&gt;
&lt;script src=&quot;https://unpkg.com/vue@3/dist/vue.global.prod.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@3.1.6/dist/vuetify.min.js&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月1日 15:56:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600890.html
匿名

发表评论

匿名网友

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

确定