最新公告
  • 欢迎您光临起源地模板网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入钻石VIP
  • Vue-cli3 + ts +ant-design-vue总结

    正文概述 掘金(李春静)   2020-12-23   1157

    1.使用 babel-plugin-import #

    babel-plugin-import 是一个用于按需加载组件代码和样式的 babel 插件

    2.修改babel.config.js文件,配置 babel-plugin-import

    module.exports = {
     presets: ["@vue/app"],
    +  plugins: [
    +    [
    +      "import",
    +      { libraryName: "ant-design-vue", libraryDirectory: "es", style: true }
    +    ]
    +  ]};
    

    并且按下面的格式引入模块。

    import Vue from 'vue'
    - import Button from 'ant-design-vue/lib/button';
    + import { Button } from 'ant-design-vue';
    - import 'ant-design-vue/dist/antd.css'  
    import App from './App'  
    Vue.component(Button.name, Button)  
    Vue.config.productionTip = false  
    new Vue({
        render: h => h(App)
      }).$mount("#app");
    

    3.按照如上引入报错 关于less-loader

    解决办法:1

    还需引入 "less","less-loader" 两个js库;并且还需在node_modules\less-loader\dist\index.js文件中添加一句js

    options.javascriptEnabled = true
    
    解决办法:2

    在根目录下新建vue.config.js:

    module.exports = {
        // 配置less
        css: {
            loaderOptions: {
                less: {
                    javascriptEnabled: true,
                }        
            }
        },
    }            
    

    开始写代码

    1.ts写法参考:https://zhuanlan.zhihu.com/p/99343202

    2.如下写法报错:Type string trivially inferred from a string literal, remove type annotation

    <script lang="ts">
    import { Component, Vue } from "vue-property-decorator";
    @Component
    export default class Login extends Vue {
      userName: string = "";
      password: string = "";
    }
    </script>
    

    解决:vue.config.js中加人:

    module.exports = {
      lintOnSave: false,
    }
    

    3.在同一个页面上切换不同路由展示不同

    路由写法:

    {
        path: '/learningCenter',
        name: 'LearningCenter',
        component: () => import('@/views/learningCenter/LearningCenter.vue'),
        children: [
          {
            path: '',
            name: 'Classroom',
            component: () => import('@/views/learningCenter/Classroom.vue')
          },
          {
            path: 'exercise',
            name: 'Exercise',
            component: () => import('@/views/learningCenter/Exercise.vue')
          },
        ]
      }
    

    页面写法:

    <router-link
       class="tab"
       :class="$route.name=='Classroom'?'nowTab':''"
       to="/learningCenter"
       >班课</router-link>
    <router-link
       class="tab"
       :class="$route.name=='Exercise'?'nowTab':''"
       to="/learningCenter/exercise"
       >练习</router-link>
    

    4.引入ant-design-vue 国际化设置报错

    Warning: [antdv: LocaleProvider] LocaleProvider is deprecated. Please use locale with ConfigProvider instead

    解决:

    Components-ant.ts(按需加载antd的地方)加入并使用:ConfigProvider Shims-vue.d.ts 写入

    declare module 'ant-design-vue/es/locale/zh_CN' {
      const Ant: any
      export default Ant;
    }
    

    app.vue 页面

    <template>
      <a-config-provider :locale="locale">
        <div id="app" class="flex flex_column"></div>
      </a-config-provider>
    </template>
    <script lang="ts">
    import zhCN from "ant-design-vue/es/locale/zh_CN";
    import moment from "moment";
    import "moment/locale/zh-cn";
    import { Component, Vue } from "vue-property-decorator";
    
    moment.locale("zh-cn");
    @Component
    export default class App extends Vue {
      locale = zhCN;
    }
    </script>
    

    5.在当前页面跳转到本页面报错

    Uncaught (in promise) Error: Avoided redundant navigation to current location: "/learningCenter"

    解决:

    在路由的index.ts文件上添加

    const originalPush = VueRouter.prototype.push
    VueRouter.prototype.push = function push(location: string) {
      return originalPush.call(this, location).catch((err: any) => err)
    }
    

    6.eslint提示:类型“void”上不存在属性“catch”。ts(2339)

    原因:未声明类型

    解决:

    const originalPush: any = VueRouter.prototype.push
    VueRouter.prototype.push = function push(location: string) {
      return originalPush.call(this, location).catch((err: any) => err)
    }
    

    7.run-time报错

    Vue-cli3 + ts +ant-design-vue总结

    解决:

    // vue.config.js
    module.exports = {
    runtimeCompiler: true,
    }
    

    8. Warning: Each record in table should have a unique key prop,or set rowKey to an unique primary key.

    Warning: Each record in dataSource of table should have a unique key prop, or set rowKey of Table to an unique primary key,

    解决:

    给table的data加上key

    res.testpaper_quote_vos.map((i: any) => {
              i.key = i.testpaper_id;
     });
     this.data = res.testpaper_quote_vos;
    

    8.@watch

    9.锚点

    (document.querySelector(idname) as Element).scrollIntoView(true);
    

    10.https://www.cnblogs.com/guojikun/p/12564665.html


    起源地下载网 » Vue-cli3 + ts +ant-design-vue总结

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    模板不会安装或需要功能定制以及二次开发?
    请QQ联系我们

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者

    请选择支付方式

    ×
    迅虎支付宝
    迅虎微信
    支付宝当面付
    余额支付
    ×
    微信扫码支付 0 元