将新闻提要显示为桌面的3列,移动vue的3行

发布于 2025-02-08 20:45:50 字数 3265 浏览 0 评论 0原文

我正在尝试将新闻显示为移动视图中的三行,我使用Vueslickcarousel将新闻显示为桌面上的三列,我试图为不同的屏幕尺寸添加断点,但它不起作用(没有显示任何内容在手机上)

这是新闻发布的代码:

 <div class="md:col-span-12 col-span-12">
            <div>
              <div
                v-if="postloader"
                class="grid lg:grid-cols-3 grid-cols-1 gap-5"
              >
                <div v-for="n in 3" :key="n">
                  <v-skeleton-loader
                    type="card-avatar, article, actions"
                  ></v-skeleton-loader>
                </div>
              </div>
              <div v-if="!postloader">
                  <VueSlickCarousel v-bind="PostSettings">
                 
                    <div
                      v-for="post of posts.slice(0, 3)"
                      :key="post.slug"
                      class="slick-item"
                    >
                      <div class="md:px-4 px-0">
                        <nuxt-link
                          :to="`/news-updates/${post.slug}`"
                          class="ma-12"
                        >
                          <img
                            class="md:h-52 h-full w-full object-cover"
                            :src="
                              post._embedded['wp:featuredmedia']['0'].source_url
                            "
                            alt="News"
                          />
                          <h3 class="text-xl mt-4">
                            {{ post.title.rendered }}
                          </h3>
                          <p
                            class="excerpt mt-2"
                            v-html="post.excerpt.rendered.slice(0, 160)"
                          ></p>
                          <p class="block font-bold mt-6 hover:opacity-80">
                            Read More <v-icon>mdi-chevron-double-right</v-icon>
                          </p>
                        </nuxt-link>
                      </div>
                    </div>
              </VueSlickCarousel>
                
              </div>
            </div> 

这是我要用于断点的JS:

PostSettings: {
    arrows: false,
    dots: false,
    autoplay: false,
    slidesToShow: 3,
    slidesToScroll: 1,
    focusOnSelect: true,
    responsive: [
      {
        breakpoint: 1024,
        settings: {
          arrows: false,
          dots: false,
          autoplay: true,
          slidesToShow: 2,
          slidesToScroll: 1,
          focusOnSelect: true,
        },
      },
      {
        breakpoint: 600,
        settings: {
          arrows: false,
          dots: false,
          autoplay: true,
          slidesToShow: 1,
          slidesToScroll: 1,
          focusOnSelect: true,
        },
      },
      {
        breakpoint: 480,
        settings: {
          arrows: false,
          dots: false,
          autoplay: true,
          slidesToShow: 1,
          slidesToScroll: 1,
          focusOnSelect: true,
        },
      },
    ],
  },

如果删除标签,则在台式机上伸展的新闻显示并正确地在移动设备上(请参阅Loom),这些断点似乎不会 方法可以使用尾管以桌面/移动设备的不同格式显示新闻

为了工作,是否有一种 vid

I am trying to get my news to display as three rows in mobile view, I have used VueSlickCarousel to make the news display as three columns on desktop, I have tried to add breakpoints for the different screen sizes but its not working (nothing is displayed on mobile)

This is the code for the news posts:

 <div class="md:col-span-12 col-span-12">
            <div>
              <div
                v-if="postloader"
                class="grid lg:grid-cols-3 grid-cols-1 gap-5"
              >
                <div v-for="n in 3" :key="n">
                  <v-skeleton-loader
                    type="card-avatar, article, actions"
                  ></v-skeleton-loader>
                </div>
              </div>
              <div v-if="!postloader">
                  <VueSlickCarousel v-bind="PostSettings">
                 
                    <div
                      v-for="post of posts.slice(0, 3)"
                      :key="post.slug"
                      class="slick-item"
                    >
                      <div class="md:px-4 px-0">
                        <nuxt-link
                          :to="`/news-updates/${post.slug}`"
                          class="ma-12"
                        >
                          <img
                            class="md:h-52 h-full w-full object-cover"
                            :src="
                              post._embedded['wp:featuredmedia']['0'].source_url
                            "
                            alt="News"
                          />
                          <h3 class="text-xl mt-4">
                            {{ post.title.rendered }}
                          </h3>
                          <p
                            class="excerpt mt-2"
                            v-html="post.excerpt.rendered.slice(0, 160)"
                          ></p>
                          <p class="block font-bold mt-6 hover:opacity-80">
                            Read More <v-icon>mdi-chevron-double-right</v-icon>
                          </p>
                        </nuxt-link>
                      </div>
                    </div>
              </VueSlickCarousel>
                
              </div>
            </div> 

And this is the js I am trying to use for the breakpoints:

PostSettings: {
    arrows: false,
    dots: false,
    autoplay: false,
    slidesToShow: 3,
    slidesToScroll: 1,
    focusOnSelect: true,
    responsive: [
      {
        breakpoint: 1024,
        settings: {
          arrows: false,
          dots: false,
          autoplay: true,
          slidesToShow: 2,
          slidesToScroll: 1,
          focusOnSelect: true,
        },
      },
      {
        breakpoint: 600,
        settings: {
          arrows: false,
          dots: false,
          autoplay: true,
          slidesToShow: 1,
          slidesToScroll: 1,
          focusOnSelect: true,
        },
      },
      {
        breakpoint: 480,
        settings: {
          arrows: false,
          dots: false,
          autoplay: true,
          slidesToShow: 1,
          slidesToScroll: 1,
          focusOnSelect: true,
        },
      },
    ],
  },

If I remove the tag the news displays stretched on desktop and correctly on mobile (see loom), the breakpoints dont seem to be working, is there a way to use tailwind to display the news in different formats for desktop / mobile

Loom demo vid

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野心澎湃 2025-02-15 20:45:50

这是您问题的答案

有没有一种方法可以使用尾风以桌面 /移动设备以不同的格式显示新闻?< / p>

是的,您可以使用屏幕断点。下面是当您在移动视图中具有6x2网格时的实现,桌面中的4x3和2x6在大型桌面视图中。

<script src="https://cdn.tailwindcss.com"></script>
<div class="p-5">
  <div class="grid grid-cols-2 md:grid-cols-3 xl:grid-cols-6 gap-2">
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">01</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">02</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">03</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">04</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">05</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">06</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">07</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">08</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">09</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">10</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">11</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">12</div>
  </div>
</div>

This is the answer for your question

Is there a way to use tailwind to display the news in different formats for desktop / mobile?

Yes you can have by using screen breakpoints. Below is the implementation when you have 6x2 grid in mobile view, 4x3 in desktop and 2x6 in large desktop view.

<script src="https://cdn.tailwindcss.com"></script>
<div class="p-5">
  <div class="grid grid-cols-2 md:grid-cols-3 xl:grid-cols-6 gap-2">
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">01</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">02</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">03</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">04</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">05</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">06</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">07</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">08</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">09</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">10</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">11</div>
      <div class="h-10 w-16 bg-pink-800 text-center text-white pt-2">12</div>
  </div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文