当前位置:   article > 正文

vuetify-使用详细入门教程_vuetifyjs

vuetifyjs

写在前面的话,公司工作很久了,一直都没有改过自己的技术栈,才觉得慢慢的落后于潮流,也知道自己的技术栈很老旧,想过要重构项目,但是项目周期时间一直不许,学习vue只能在下班的时间里面,这两年也断断续续的用过一些框架,但最后还是选中了vuetify。

vuetify

推荐指数:star:25.4k
适用:移动PC多端支持

GitHub地址:https://github.com/vuetifyjs/vuetify
官网地址:https://vuetifyjs.com/zh-Hans/

来看看官网是怎么介绍的吧:这是世界上最流行的 Vue.js 框架,用于构建功能丰富、快速的应用程序。

Vuetify确实是一款非常精致的UI框架,它提供了很多常用的组件,依靠Material Design的设计优势,让你无需编写一行css代码就可以得到非常美观的界面功能。响应式做的不错,移动PC多端支持,配置灵活,组件也挺多的,足够现代,功能全面vuetify,一直用一直爽,强烈推荐vuetify。

步骤:
1:以管理员的身份打开cmd,进入d盘
使用 Vue CLI 创建一个新的 Vue.js 项目

vue create vuetify-app
  • 1

img

完成以后,可以看到D盘出现的初始化的项目了

img

2:根据提示
运行

cd vuetify-app



npm run serve
  • 1
  • 2
  • 3
  • 4
  • 5

img

启动成功

img

打开浏览器,输入地址,可以访问了

img

3:将项目导入编辑器
在编辑器里面打开终端

vue add vuetify
  • 1

img

一路回车,以下就是安装完成了

img

4:根据文档,写一个表格分页

<template>
  <v-data-table
    :headers="headers"
    :items="desserts"
    :items-per-page="5"
    class="elevation-1"
  ></v-data-table>
</template>
<script>
  export default {
    data () {
      return {
        headers: [
          {
            text: 'Dessert (100g serving)',
            align: 'start',
            sortable: false,
            value: 'name',
          },
          { text: 'Calories', value: 'calories' },
          { text: 'Fat (g)', value: 'fat' },
          { text: 'Carbs (g)', value: 'carbs' },
          { text: 'Protein (g)', value: 'protein' },
          { text: 'Iron (%)', value: 'iron' },
        ],
        desserts: [
          {
            name: 'Frozen Yogurt',
            calories: 159,
            fat: 6.0,
            carbs: 24,
            protein: 4.0,
            iron: '1%',
          },
          {
            name: 'Ice cream sandwich',
            calories: 237,
            fat: 9.0,
            carbs: 37,
            protein: 4.3,
            iron: '1%',
          },
          {
            name: 'Eclair',
            calories: 262,
            fat: 16.0,
            carbs: 23,
            protein: 6.0,
            iron: '7%',
          },
          {
            name: 'Cupcake',
            calories: 305,
            fat: 3.7,
            carbs: 67,
            protein: 4.3,
            iron: '8%',
          },
          {
            name: 'Gingerbread',
            calories: 356,
            fat: 16.0,
            carbs: 49,
            protein: 3.9,
            iron: '16%',
          },
          {
            name: 'Jelly bean',
            calories: 375,
            fat: 0.0,
            carbs: 94,
            protein: 0.0,
            iron: '0%',
          },
          {
            name: 'Lollipop',
            calories: 392,
            fat: 0.2,
            carbs: 98,
            protein: 0,
            iron: '2%',
          },
          {
            name: 'Honeycomb',
            calories: 408,
            fat: 3.2,
            carbs: 87,
            protein: 6.5,
            iron: '45%',
          },
          {
            name: 'Donut',
            calories: 452,
            fat: 25.0,
            carbs: 51,
            protein: 4.9,
            iron: '22%',
          },
          {
            name: 'KitKat',
            calories: 518,
            fat: 26.0,
            carbs: 65,
            protein: 7,
            iron: '6%',
          },
        ],
      }
    },
  }
</script>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111

img

5:上面是一个静态的表格,怎么写成一个请求json数据,然后渲染数据的格式呢,这里就要用到常用的axios请求方法了。

安装axios

npm install axios --save
  • 1

img

在public底下新建一个static静态文件夹,存放json数据
,准备json数据数据格式如下:

img

[{
    "name": "22物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
},{
    "name": "23物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
},{
    "name": "24物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
},{
    "name": "25物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
},{
    "name": "26物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
},{
    "name": "27物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
},{
    "name": "28物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
},{
    "name": "29物联",
    "calories": 1,
    "fat": "DDDDD",
    "carbs": 1,
    "protein": "DDDD",
    "iron": "DDDDD"
}]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

代码示例

<template>
  <v-data-table :headers="headers" :items="desserts" :items-per-page="5" class="elevation-1"></v-data-table>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      headers: [
        {
          text: "Dessert (100g serving)",
          align: "start",
          sortable: false,
          value: "name"
        },
        { text: "Calories", value: "calories" },
        { text: "Fat (g)", value: "fat" },
        { text: "Carbs (g)", value: "carbs" },
        { text: "Protein (g)", value: "protein" },
        { text: "Iron (%)", value: "iron" }
      ],
      desserts: []
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      axios.get("/static/mock.json").then(
        response => {
          console.log(response.data);
          this.desserts = response.data;
        },
        error => {  
          console.log(error);
        }
      );
    }
  }
};
</script>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

效果如下

img

OK,完成。

img

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号