search
HomeWeb Front-endVue.jsHow to implement headline-like page design in Vue?

Vue is a framework-based progressive JavaScript library that makes it easy to build complex single-page applications. In web development, headline-like page design has become a common trend because it can provide a better user experience and make it easier for users to browse and find interesting content.

This article will introduce how to use the Vue framework to implement headline-like page design, including the design of homepage, content page and search page. First, we need to install Vue CLI, which is a command line tool officially provided by Vue to quickly build Vue applications. The specific method is as follows:

  1. Install Node.js and npm.

If you have not installed Node.js and npm, you can download and install it from the Node.js official website.

  1. Install Vue CLI.

You can use the following command to install Vue CLI globally:

npm install -g @vue/cli
  1. Create project.

You can use the following command to create a new Vue project:

vue create my-project

Where, my-project is the name of the project. When creating a project, you can choose to use the default settings or manually configure some options.

Now, let us start to implement the page design that imitates headlines.

  1. Homepage design

First, we need to create a homepage, which should have a header, navigation bar, content list, and tail. Using Vue, we can easily create this page.

The header part can be implemented using components, the code is as follows:

<template>
  <div class="header">
    <div class="logo">
      <img src="/static/imghwm/default1.png"  data-src="./assets/logo.png"  class="lazy" alt="logo">
    </div>
    <div class="title">TODAY</div>
    <div class="search">
      <input type="text">
      <button>搜索</button>
    </div>
  </div>
</template>

The navigation bar part includes multiple tabs, we can use Vue Router to implement it. When creating the project with Vue CLI, we have already installed Vue Router and only need to configure routing in App.vue. The code is as follows:

<template>
  <div>
    <router-link to="/">主页</router-link>
    <router-link to="/news">新闻</router-link>
    <router-link to="/video">视频</router-link>
    <router-link to="/my">我的</router-link>
    <router-link to="/publish">发布</router-link>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'App',
  components: {},
};
</script>

The content list section includes multiple articles. We can use Vue to dynamically render these articles and add some transition effects to improve the user experience. The code is as follows:

<template>
  <div class="article-list">
    <transition-group name="fade">
      <div class="article" v-for="article in articles" :key="article.id">
        <div class="image">
          <img src="/static/imghwm/default1.png"  data-src="article.image"  class="lazy"  : alt="article-image">
        </div>
        <div class="title">{{ article.title }}</div>
        <div class="summary">{{ article.summary }}</div>
        <div class="info">
          <div class="time">{{ article.time }}</div>
          <div class="source">{{ article.source }}</div>
          <div class="comment">{{ article.comment }}评论</div>
          <div class="like">{{ article.like }}赞</div>
        </div>
      </div>
    </transition-group>
  </div>
</template>

<script>
export default {
  name: 'ArticleList',
  data() {
    return {
      articles: [
        {
          id: 1,
          image: './assets/article1.jpg',
          title: '文章标题1',
          summary: '文章摘要1',
          time: '10分钟前',
          source: '文章来源1',
          comment: 100,
          like: 200,
        },
        {
          id: 2,
          image: './assets/article2.jpg',
          title: '文章标题2',
          summary: '文章摘要2',
          time: '20分钟前',
          source: '文章来源2',
          comment: 150,
          like: 250,
        },
        // 可以添加更多的文章
      ],
    };
  },
};
</script>

<style scoped>
/* 添加一些过渡效果 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>

The tail part includes some common links and social media icons, the code is as follows:

<template>
  <div class="footer">
    <div class="link">
      <a href="#">关于我们</a>
      <a href="#">联系我们</a>
      <a href="#">隐私政策</a>
      <a href="#">版权声明</a>
      <a href="#">广告服务</a>
      <a href="#">招聘信息</a>
    </div>
    <div class="social">
      <p>关注我们:</p>
      <div class="icon">
        <a href="#"><i class="fab fa-weibo"></i></a>
        <a href="#"><i class="fab fa-weixin"></i></a>
        <a href="#"><i class="fab fa-qq"></i></a>
        <a href="#"><i class="fab fa-douban"></i></a>
        <a href="#"><i class="fab fa-linkedin-in"></i></a>
        <a href="#"><i class="fab fa-github"></i></a>
      </div>
    </div>
  </div>
</template>
  1. Content page design

The content page should Includes article details, related articles and comments. We can use Vue Router to implement jumps and pass parameters. The code is as follows:

<template>
  <div class="article-page">
    <div class="article-header">
      <div class="title">{{ article.title }}</div>
      <div class="info">
        <div class="time">{{ article.time }}</div>
        <div class="source">{{ article.source }}</div>
        <div class="comment">{{ article.comment }}评论</div>
        <div class="like">{{ article.like }}赞</div>
      </div>
    </div>
    <div class="article-body">
      <div class="image">
        <img src="/static/imghwm/default1.png"  data-src="article.image"  class="lazy"  : alt="article-image">
      </div>
      <div class="content">
        {{ article.content }}
      </div>
    </div>
    <div class="article-footer">
      <div class="related-articles">
        <div class="title">相关文章</div>
        <div class="list">
          <div class="related-article" v-for="relatedArticle in relatedArticles" :key="relatedArticle.id">
            <div class="image">
              <img src="/static/imghwm/default1.png"  data-src="relatedArticle.image"  class="lazy"  : alt="article-image">
            </div>
            <div class="title">{{ relatedArticle.title }}</div>
          </div>
        </div>
      </div>
      <div class="comments">
        <div class="title">用户评论</div>
        <div class="list">
          <div class="comment" v-for="comment in comments" :key="comment.id">
            <div class="avatar">
              <img src="/static/imghwm/default1.png"  data-src="comment.avatar"  class="lazy"  : alt="user-avatar">
            </div>
            <div class="content">
              <div class="name">{{ comment.name }}</div>
              <div class="time">{{ comment.time }}</div>
              <div class="text">{{ comment.text }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ArticlePage',
  data() {
    return {
      article: {
        id: 1,
        image: './assets/article1.jpg',
        title: '文章标题1',
        content: '文章内容1',
        time: '10分钟前',
        source: '文章来源1',
        comment: 100,
        like: 200,
      },
      relatedArticles: [
        {
          id: 2,
          image: './assets/article2.jpg',
          title: '文章标题2',
        },
        {
          id: 3,
          image: './assets/article3.jpg',
          title: '文章标题3',
        },
        // 可以添加更多的相关文章
      ],
      comments: [
        {
          id: 1,
          avatar: './assets/avatar1.jpg',
          name: '用户1',
          time: '1小时前',
          text: '评论内容1',
        },
        {
          id: 2,
          avatar: './assets/avatar2.jpg',
          name: '用户2',
          time: '2小时前',
          text: '评论内容2',
        },
        // 可以添加更多的评论
      ],
    };
  },
};
</script>
  1. Search page design

The search page should include a search box, search button and search results. We can use Vue to dynamically render search results. The code is as follows:

<template>
  <div class="search-page">
    <div class="search-box">
      <input type="text" v-model="query" placeholder="输入搜索内容">
      <button @click="search">搜索</button>
    </div>
    <div class="search-result">
      <div class="title">搜索结果</div>
      <div class="list">
        <div class="result" v-for="result in results" :key="result.id">
          <div class="image">
            <img src="/static/imghwm/default1.png"  data-src="result.image"  class="lazy"  : alt="article-image">
          </div>
          <div class="title">{{ result.title }}</div>
          <div class="source">{{ result.source }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SearchPage',
  data() {
    return {
      query: '',
      results: [],
    };
  },
  methods: {
    search() {
      // 模拟搜索结果
      this.results = [
        {
          id: 1,
          image: './assets/article1.jpg',
          title: '搜索结果1',
          source: '文章来源1',
        },
        {
          id: 2,
          image: './assets/article2.jpg',
          title: '搜索结果2',
          source: '文章来源2',
        },
        // 可以添加更多的搜索结果
      ];
    },
  },
};
</script>

So far, we have implemented a headline-like page design. Using the Vue framework, you can quickly and easily implement complex page designs, improving development efficiency and user experience. I hope this article can help you better understand the Vue framework and its applications.

The above is the detailed content of How to implement headline-like page design in Vue?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Vue.js vs. Backend Frameworks: Clarifying the DistinctionVue.js vs. Backend Frameworks: Clarifying the DistinctionApr 25, 2025 am 12:05 AM

Vue.js is a front-end framework, and the back-end framework is used to handle server-side logic. 1) Vue.js focuses on building user interfaces and simplifies development through componentized and responsive data binding. 2) Back-end frameworks such as Express and Django handle HTTP requests, database operations and business logic, and run on the server.

Vue.js and the Frontend Stack: Understanding the ConnectionsVue.js and the Frontend Stack: Understanding the ConnectionsApr 24, 2025 am 12:19 AM

Vue.js is closely integrated with the front-end technology stack to improve development efficiency and user experience. 1) Construction tools: Integrate with Webpack and Rollup to achieve modular development. 2) State management: Integrate with Vuex to manage complex application status. 3) Routing: Integrate with VueRouter to realize single-page application routing. 4) CSS preprocessor: supports Sass and Less to improve style development efficiency.

Netflix: Exploring the Use of React (or Other Frameworks)Netflix: Exploring the Use of React (or Other Frameworks)Apr 23, 2025 am 12:02 AM

Netflix chose React to build its user interface because React's component design and virtual DOM mechanism can efficiently handle complex interfaces and frequent updates. 1) Component-based design allows Netflix to break down the interface into manageable widgets, improving development efficiency and code maintainability. 2) The virtual DOM mechanism ensures the smoothness and high performance of the Netflix user interface by minimizing DOM operations.

Vue.js and the Frontend: A Deep Dive into the FrameworkVue.js and the Frontend: A Deep Dive into the FrameworkApr 22, 2025 am 12:04 AM

Vue.js is loved by developers because it is easy to use and powerful. 1) Its responsive data binding system automatically updates the view. 2) The component system improves the reusability and maintainability of the code. 3) Computing properties and listeners enhance the readability and performance of the code. 4) Using VueDevtools and checking for console errors are common debugging techniques. 5) Performance optimization includes the use of key attributes, computed attributes and keep-alive components. 6) Best practices include clear component naming, the use of single-file components and the rational use of life cycle hooks.

The Power of Vue.js on the Frontend: Key Features and BenefitsThe Power of Vue.js on the Frontend: Key Features and BenefitsApr 21, 2025 am 12:07 AM

Vue.js is a progressive JavaScript framework suitable for building efficient and maintainable front-end applications. Its key features include: 1. Responsive data binding, 2. Component development, 3. Virtual DOM. Through these features, Vue.js simplifies the development process, improves application performance and maintainability, making it very popular in modern web development.

Is vue.js better than React?Is vue.js better than React?Apr 20, 2025 am 12:05 AM

Vue.js and React each have their own advantages and disadvantages, and the choice depends on project requirements and team conditions. 1) Vue.js is suitable for small projects and beginners because of its simplicity and easy to use; 2) React is suitable for large projects and complex UIs because of its rich ecosystem and component design.

Vue.js's Function: Enhancing User Experience on the FrontendVue.js's Function: Enhancing User Experience on the FrontendApr 19, 2025 am 12:13 AM

Vue.js improves user experience through multiple functions: 1. Responsive system realizes real-time data feedback; 2. Component development improves code reusability; 3. VueRouter provides smooth navigation; 4. Dynamic data binding and transition animation enhance interaction effect; 5. Error processing mechanism ensures user feedback; 6. Performance optimization and best practices improve application performance.

Vue.js: Defining Its Role in Web DevelopmentVue.js: Defining Its Role in Web DevelopmentApr 18, 2025 am 12:07 AM

Vue.js' role in web development is to act as a progressive JavaScript framework that simplifies the development process and improves efficiency. 1) It enables developers to focus on business logic through responsive data binding and component development. 2) The working principle of Vue.js relies on responsive systems and virtual DOM to optimize performance. 3) In actual projects, it is common practice to use Vuex to manage global state and optimize data responsiveness.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software