当前位置: 首页 > article >正文

标题点击可跳转网页

要实现点击标题跳转到网页的功能,你可以在Vue组件中使用<a>标签(锚点标签)并设置href属性为网页的URL。如果你希望使用uni-app的特性来控制页面跳转,可以使用uni.navigateTo方法(这适用于uni-app环境,如微信小程序、App等)。

以下是两种实现方式的示例:

使用HTML锚点标签跳转

 

html

<template>
  <view class="news-list">
    <!-- 新闻列表 -->
    <view class="news-item" v-for="(news, index) in newsList" :key="index">
      <!-- 使用a标签包裹标题,点击时跳转到网页 -->
      <a :href="news.url" target="_blank" class="news-title">{{ news.title }}</a>
      <view class="news-author">作者:{{ news.author }}</view>
      <!-- 新闻视频 -->
      <view class="news-video">
        <video :src="news.videoUrl" controls></video>
      </view>
    </view>
  </view>
</template>

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

// 假设的新闻数据
const newsList = ref([
  {
    title: '新闻1',
    author: '石平',
    videoUrl: 'https://www.example.com/video1.mp4', // 视频链接
    url: 'https://www.example.com/news1' // 新闻详情页链接
  },
  {
    title: '新闻2',
    author: '石平',
    videoUrl: 'https://www.example.com/video2.mp4', // 视频链接
    url: 'https://www.example.com/news2' // 新闻详情页链接
  },
  // 更多新闻...
]);
</script>

<style>
/* 样式 */
</style>

在这个示例中,<a>标签的href属性被设置为新闻项的url属性,这样点击标题时就会打开一个新的浏览器标签页并跳转到指定的URL。

使用uni-app的uni.navigateTo方法跳转

如果你的应用是在一个App或小程序环境中运行,你可能希望使用uni-app的页面导航方法来控制页面跳转:

 

html

<template>
  <view class="news-list">
    <!-- 新闻列表 -->
    <view class="news-item" v-for="(news, index) in newsList" :key="index">
      <!-- 使用点击事件绑定跳转方法 -->
      <view @click="navigateToNews(news.url)" class="news-title">{{ news.title }}</view>
      <view class="news-author">作者:{{ news.author }}</view>
      <!-- 新闻视频 -->
      <view class="news-video">
        <video :src="news.videoUrl" controls></video>
      </view>
    </view>
  </view>
</template>

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

// 假设的新闻数据
const newsList = ref([
  {
    title: '新闻1',
    author: '石平',
    videoUrl: 'https://www.example.com/video1.mp4', // 视频链接
    url: 'https://www.example.com/news1' // 新闻详情页链接
  },
  {
    title: '新闻2',
    author: '石平',
    videoUrl: 'https://www.example.com/video2.mp4', // 视频链接
    url: 'https://www.example.com/news2' // 新闻详情页链接
  },
  // 更多新闻...
]);

// 导航到新闻详情页的方法
const navigateToNews = (url) => {
  uni.navigateTo({
    url: url
  });
};
</script>

<style>
/* 样式 */
</style>

在这个示例中,点击标题时会触发navigateToNews方法,该方法使用uni.navigateTo来跳转到指定的URL。这种方法适用于uni-app环境,允许你在App或小程序中进行页面跳转。


http://www.kler.cn/a/369316.html

相关文章:

  • BUUCTF之web篇
  • java小白到架构师技术图谱
  • 【我的创作纪念日1024】
  • PHP-FPM 性能配置优化
  • UML外卖系统报告(包含具体需求分析)
  • 鸿蒙-窗口什么时候有叉按钮
  • 【32】C++流
  • ETLCloud+Doris组合:数据集成,更简单更高效
  • Linux系统基础-进程间通信(5)_模拟实现命名管道和共享内存
  • 【ubuntu18.04】ubuntu18.04 编译LightGBM操作说明
  • 大众点评 web mtgsig 1.2分析
  • AI跟踪报道第62期-本周AI新闻: 微软推出Copilot的AI Agent和Computer Control
  • 【学术会议投稿】Imagen:重塑图像生成领域的革命性突破
  • 深入理解Rust中的指针:裸指针 智能指针
  • Docker:容器
  • 2024 AI 时代:科学计算服务器——科技创新核心动力源
  • k8s 二进制部署安装(三)
  • 08 实战:色彩空间展示(本程序以视频为主)
  • 基于 matlab 计算 TPI(地形位置指数)
  • 2024-10-24 问AI: [AI面试题] 解释自然语言处理 (NLP) 的概念
  • AAPL: Adding Attributes to Prompt Learning for Vision-Language Models
  • RTOS性能测试:R-Rhealstone
  • 从可逆计算看低代码
  • C语言复习总结超详细版(1)小白转身即变 有实例超级详细
  • 多态的体现
  • 【数据结构与算法】第5课—数据结构之双链表