当前位置:   article > 正文

vue3-element-plus使用_vue3 + element-plus

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>

运行效果:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/644773
推荐阅读
相关标签
  

闽ICP备14008679号