Cannot read properties of undefined (reading ‘click‘) | (reading ‘touchstart‘)| (reading ‘prototype‘

本文介绍了一位开发者在使用Vant组件时遇到的Cannotreadpropertiesofundefined错误,通过升级Vue.js版本至2.6.12解决了问题。详细步骤包括问题复现、版本对比和解决方法。实例展示了如何在单页面应用中简单使用Vue和Vant。
摘要由CSDN通过智能技术生成

1.遇到问题

使用单页面vue,vant发现报错

Cannot read properties of undefined (reading ‘click’)
Uncaught TypeError: Cannot read properties of undefined (reading ‘touchstart’)
Cannot read properties of undefined (reading ‘prototype’)

2.解决过程

下载最新版本vue2发现不再报错,使用2014-2017版本的vue2则会报错。

3.如何解决

将 * Vue.js v2.2.2 * © 2014-2017 Evan You 版本的vue.min.js文件换成 * Vue.js v2.6.12* © 2014-2020 Evan You.即可。

4.简单使用单页面vue,vant实例

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <link rel="stylesheet" href="./css/vantCss.css">
    <script src="./js/vue.min.js"></script>
    <script src="./js/vant.min.js"></script> -->

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.10/lib/index.css" rel="external nofollow" target="_blank" />
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://cdn.jsdelivr.net/npm/vant@2.10/lib/vant.min.js" rel="external nofollow"></script>
</head>

<body>
    <div id="app"></div>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
            },
            methods: {
            },
            created() {
                vant.Dialog.alert({
                    message: '弹窗内容'
                }).then(() => {
                    // on close
                });
            },
        })
    </script>
</body>

</html>   

5. Cannot read properties of undefined (reading ‘prototype’)

vue版本问题

单页面使用vue,element

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>

<body>
    <div id="app">
        <el-button @click="visible = true">Button</el-button>
        <el-dialog :visible.sync="visible" title="Hello world">
            <p>Try Element</p>
        </el-dialog>
        <i class="el-icon-edit"></i>
        <i class="el-icon-share"></i>
        <i class="el-icon-delete"></i>
        <el-button type="primary" icon="el-icon-search">搜索</el-button>

    </div>
</body>
<!-- 生产环境版本,优化了尺寸和速度 -->
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    new Vue({
        el: '#app',
        data: function () {
            return { visible: false }
        }
    })
</script>

</html>
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
05-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值