Vue 项目 引入第三方饿了吗组件(ElementUI)

以你之姓@ 2023-10-17 14:12 89阅读 0赞

第一步:新建Vue 项目(详细创建步骤请参考:http://blog.csdn.net/zhouzhiwengang/article/details/70344522)

  1. #创建一个基于webpack模板的新项目
  2. vue init webpack d:\nodeworkspace\nodeone
  3. # 切换至项目路径
  4. cd d:\nodeworkspace\nodeone
  5. # 安装项目依赖文件
  6. cnpm install
  7. # 项目启动
  8. cnpm run dev

第二步:引入饿了吗组件(ElementUI)

1、打开cmd 窗口,切换到vue 所在目录,执行如下指令: cnpm i element-ui s

Center

第三步:vue 项目引用ElementUI.,(注意红色字体部分)

src/router/index.js

  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import Hello from '@/components/Hello'
  4. import ElementUI from 'element-ui'
  5. import 'element-ui/lib/theme-default/index.css'
  6. Vue.use(Router)
  7. Vue.use(ElementUI)
  8. export default new Router({
  9. routes: [
  10. {
  11. path: '/',
  12. name: 'Hello',
  13. component: Hello
  14. }
  15. ]
  16. })

组件引用相关样式:src/components/Hello.vue

  1. <template>
  2. <div class="hello">
  3. <!-- 文本绑定-->
  4. <h1>{
  5. { msg }}</h1>
  6. <!--html 绑定-->
  7. <div v-html="message"></div>
  8. <h2>Essential Links</h2>
  9. <ul>
  10. <li><a href="https://vuejs.org" target="_blank">Core Docs</a></li>
  11. <li><a href="https://forum.vuejs.org" target="_blank">Forum</a></li>
  12. <li><a href="https://gitter.im/vuejs/vue" target="_blank">Gitter Chat</a></li>
  13. <li><a href="https://twitter.com/vuejs" target="_blank">Twitter</a></li>
  14. <br>
  15. <li><a href="http://vuejs-templates.github.io/webpack/" target="_blank">Docs for This Template</a></li>
  16. </ul>
  17. <h2>Ecosystem</h2>
  18. <ul>
  19. <li><a href="http://router.vuejs.org/" target="_blank">vue-router</a></li>
  20. <li><a href="http://vuex.vuejs.org/" target="_blank">vuex</a></li>
  21. <li><a href="http://vue-loader.vuejs.org/" target="_blank">vue-loader</a></li>
  22. <li><a href="https://github.com/vuejs/awesome-vue" target="_blank">awesome-vue</a></li>
  23. </ul>
  24. <el-button type="primary">主要按钮</el-button>
  25. <el-button type="text">文字按钮</el-button>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'hello',
  31. data () {
  32. return {
  33. msg: '欢迎来到菜鸟教程',
  34. message:'<p>欢迎来到菜鸟A大队</p>',
  35. }
  36. }
  37. }
  38. </script>
  39. <!-- Add "scoped" attribute to limit CSS to this component only -->
  40. <style scoped>
  41. h1, h2 {
  42. font-weight: normal;
  43. }
  44. ul {
  45. list-style-type: none;
  46. padding: 0;
  47. }
  48. li {
  49. display: inline-block;
  50. margin: 0 10px;
  51. }
  52. a {
  53. color: #42b983;
  54. }
  55. </style>

效果展示:

Center 1

发表评论

表情:
评论列表 (有 0 条评论,89人围观)

还没有评论,来说两句吧...

相关阅读