• 04-vue-cli-启动配置和静态资源配置


    一.启动配置

    1、index.js中配置

    Node JS服务器的地址,端口号,浏览器启动配置,如下图

    2.导入hello组件的方式:

    1. #hello.vue
    2. <script>
    3. // js代码
    4. script>
    5. <style>
    6. /* 样式 */
    7. style>
    1. #index.js
    2. import Vue from 'vue'
    3. import Router from 'vue-router'
    4. /* 配置地址,叫组件
    5. 第一种:导入hello组件
    6. */
    7. import hello from '../components/demo/hello.vue'
    8. /*
    9. 第二种:导入hello组件
    10. */
    11. import hello from '@/components/demo/hello'
    12. Vue.use(Router)
    13. export default new Router({
    14. routes: [
    15. {
    16. /* 斜杠:代表项目的默认地址 */
    17. path: '/',
    18. name: 'hello', /* 组件名称:保持名称唯一性 */
    19. component: hello /* 引入组件的别名 */
    20. }
    21. ]
    22. })

    3.案例:基于vue-cli的登录页面设计

    需求:创建一个登录页面,用nodejs作为服务器访问,步骤如下:

    在components/demo目录下创建hello01.vue页面,需要注意事项

    1. 表单标签一定要有一个父级标签,例如:不能直接写input标签,而是在input标签上加上div标签

    1. <script>
    2. // 默认导出,ES6语法
    3. export default {
    4. name:"", //描述组件的名称
    5. data(){ //数据绑定,对应的是data:{}
    6. return{
    7. userInfo:{ //绑定用户对象
    8. userName:"",
    9. userPwd:""
    10. }
    11. }
    12. },
    13. methods:{ //定义函数
    14. login(){ //登录,取消了function
    15. alert(this.userInfo.userName);
    16. }
    17. }
    18. }
    19. script>
    20. <style>
    21. style>

    2. 页面可以不需要定义vue绑定的标签id,因为是单页面,main.js 里面已经定义过了

    3. 需要采用ES6 语法定义js

    4. 数据绑定,方法定义,文档加载事件写法和vue略有不同,具体写法看源码

    1. import Vue from 'vue'
    2. import Router from 'vue-router'
    3. /* 配置地址,叫组件
    4. 第一种:导入hello组件
    5. */
    6. // import hello from '../components/demo/hello.vue'
    7. /*
    8. 第二种:导入hello组件
    9. */
    10. import hello from '@/components/demo/hello'
    11. /* 配置地址,叫组件
    12. 第一种:导入hello01组件
    13. */
    14. import hello01 from '../components/demo/hello01.vue'
    15. Vue.use(Router)
    16. export default new Router({
    17. routes: [
    18. {
    19. /* 斜杠:代表项目的默认地址 */
    20. path: '/',
    21. name: 'hello', /* 组件名称:保持名称唯一性 */
    22. component: hello /* 引入组件的别名 */
    23. },
    24. {
    25. path: '/hello01',
    26. name: 'hello01',
    27. component: hello01
    28. }
    29. ]
    30. })

     

    二、静态资源配置

    1.引入js方法:在static下面引入js

    📎jquery.min.jsicon-default.png?t=M85Bhttps://www.yuque.com/attachments/yuque/0/2022/js/32505142/1662566597706-314fd278-c368-4f7f-b8be-1f06c9224e18.js

    然后修改hello01.vue,引入

    1. <script>
    2. // 默认导出,ES6语法
    3. export default {
    4. name:"", //描述组件的名称
    5. data(){ //数据绑定,对应的是data:{}
    6. return{
    7. userInfo:{ //绑定用户对象
    8. userName:"",
    9. userPwd:""
    10. }
    11. }
    12. },
    13. methods:{ //定义函数
    14. login(){ //登录,取消了function
    15. var title = $("#title").text();
    16. alert(title);
    17. }
    18. }
    19. }
    20. script>
    21. <style>
    22. style>

    2.引入css的方法:针对于src/assetes目录

    在src/assets中建立css目录,然后在写一个Test.css

    .myTest{
    color: red;
    }
    

    引入的方法:

    在App.vue中引入

    应用:

    结果:

  • 相关阅读:
    分享一些走心的句子英文表达
    两台Linux服务器之间传送文件
    华为OD:VLAN资源池
    基于ABP实现DDD--领域服务、应用服务和DTO实践
    【C++笔记】C++三大特性之多态的概念、定义及使用
    数据结构之堆的实现
    湖仓一体电商项目(二十四):合并Iceberg小文件
    对象池复用实践
    java类和对象
    如何实现超大场景三维模型数据坐标转换
  • 原文地址:https://blog.csdn.net/weixin_46048259/article/details/127461719