Vue.js实现网格列表布局转换方法

前端之家收集整理的这篇文章主要介绍了Vue.js实现网格列表布局转换方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

实现效果

实现代码及注释:

布局转换 <Meta charset="utf-8"> <Meta name="viewport" content="width=device-width,initial-scale=1.0"> <Meta http-equiv="X-UA-Compatible" content="IE=edge">

<div class="bar">

<a class="list-icon" v-bind:class="{ 'active': layout == 'list'}" v-on:click="layout = 'list'">
<a class="grid-icon" v-bind:class="{ 'active': layout == 'grid'}" v-on:click="layout = 'grid'">

<ul v-if="layout == 'grid'" class="grid">

<li v-for="a in articles">
<a v-bind:href="a.url" rel="external nofollow" rel="external nofollow" target="_blank">

<ul v-if="layout == 'list'" class="list">

<li v-for="a in articles">
<a v-bind:href="a.url" rel="external nofollow" rel="external nofollow" target="_blank">

{{a.title}}

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.5/vue.min.js"&gt;
<script type="text/javascript">
var demo = new Vue({
el: '#main',data: {
// 布局形式可能的值为grid或者list
layout: 'grid',articles: [{
"title": "What You Need To Know About CSS Variables",// "url":
"image": {
"large": "https://files.jb51.cc/file_images/article/201708/15-128.png","small": "https://files.jb51.cc/file_images/article/201708/15-128.png"
}
},{
"title": "Freebie: 4 Great Looking Pricing Tables","image": {
"large": "https://files.jb51.cc/file_images/article/201708/15-128.png",{
"title": "20 Interesting JavaScript and CSS Libraries for February 2016",{
"title": "Quick Tip: The Easiest Way To Make Responsive Headers",{
"title": "Learn sql In 20 Minutes",{
"title": "Creating Your First Desktop App With HTML,JS and Electron","small": "https://files.jb51.cc/file_images/article/201708/15-128.png"
}
}]
}
});

以上这篇Vue.js实现网格列表布局转换方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

原文链接:https://www.f2er.com/vue/36863.html

猜你在找的Vue相关文章