• vue3-element-plus使用


    一、安装

    npm install element-plus --save

    二、引用

    1. import { createApp } from 'vue'
    2. import * as VueRouter from 'vue-router';
    3. import { createStore } from 'vuex'
    4. import 'element-plus/dist/index.css'
    5. import ElementPlus from 'element-plus'
    6. import App from './App.vue'
    7. import Product from './products/index.vue'
    8. import Merchands from './merchands/index.vue'
    9. const routes = [
    10. { path: '/', component: Product },
    11. { path: '/m', component: Merchands },
    12. ]
    13. const router = VueRouter.createRouter({
    14. // 4. 内部提供了 history 模式的实现。为了简单起见,我们在这里使用 hash 模式。
    15. history: VueRouter.createWebHashHistory(),
    16. routes, // `routes: routes` 的缩写
    17. })
    18. const store = createStore({
    19. state () {
    20. return {
    21. count: 0
    22. }
    23. },
    24. mutations: {
    25. increment (state) {
    26. state.count++
    27. }
    28. }
    29. })
    30. var app=createApp(App);
    31. app.use(router);
    32. app.use(store);
    33. app.use(ElementPlus);
    34. app.mount('#app');

    三、使用

    1. <template>
    2. <h1>产品管理</h1>
    3. <el-button v-on:click="increment()" type="primary">点击</el-button>
    4. <label>{{ this.$store.state.count}}</label>
    5. <el-button @click="showCreate = true" type="primary">新建</el-button>
    6. <el-dialog v-model="showCreate" title="Outer Dialog">
    7. <template #default>
    8. <el-form :model="form" label-width="120px">
    9. <el-form-item label="Activity name">
    10. <el-input v-model="form.name" />
    11. </el-form-item>
    12. </el-form>
    13. </template>
    14. <template #footer>
    15. <div class="dialog-footer">
    16. <el-button @click="showCreate = false">Cancel</el-button>
    17. <el-button type="primary" @click="save()">Save</el-button>
    18. </div>
    19. </template>
    20. </el-dialog>
    21. <div style="margin: 60px;">
    22. <el-table :data="tableData" height="250" style="width: 100%">
    23. <el-table-column prop="date" label="Date" width="180" />
    24. <el-table-column prop="name" label="Name" width="180" />
    25. <el-table-column prop="address" label="Address" />
    26. </el-table>
    27. </div>
    28. </template>
    29. <script>
    30. export default {
    31. data() {
    32. return {
    33. count: 0,
    34. showCreate: false,
    35. form: {
    36. name: ''
    37. },
    38. tableData: [{
    39. date: '2016-05-03',
    40. name: 'Tom',
    41. address: 'No. 189, Grove St, Los Angeles',
    42. }]
    43. }
    44. },
    45. methods: {
    46. save() {
    47. this.showCreate = false;
    48. this.tableData.push({
    49. date: '2016-05-03',
    50. name: this.form.name,
    51. address: 'No. 189, Grove St, Los Angeles',
    52. });
    53. this.form.name='';
    54. },
    55. increment() {
    56. this.$store.commit('increment');
    57. }
    58. }
    59. }
    60. </script>
    61. <style>
    62. </style>

    运行效果:

     

  • 相关阅读:
    2022七夕程序员必备的表白黑科技(七夕限定款)
    最新研究综述——探索基础模型中的“幻觉”现象
    Nginx配置详细解释:(6)实现反向代理服务器,动静分离,负载均衡
    Linux系统上安装python详细步骤
    产品经理基础-10运营平台端产品设计(完结~撒花~)
    Nginx架构基础
    2017年高热度编程语言简介
    金仓数据库 KingbaseES 插件参考手册 walminer
    Nacos使用和注册部分源码介绍
    1.9 - Cache
  • 原文地址:https://blog.csdn.net/xiaoxionglove/article/details/125456721