• Uncaught TypeError: Cannot read properties of undefined (reading ‘password‘)


    像使用jQuery一样或者说像Vue官方说的那样,渐进式使用Vue,于是,引入了Vue的js文件,开始了Vue编码。定义了一个Data对象,死活无法使用,一直报错,一直在网上找答案,一直没有找到,学艺不精,先看下报错信息:

    1. vue.global.3.2.38.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'password')
    2. at Proxy.render (eval at vp (vue.global.3.2.38.js:7), :100:39)
    3. at Wn (vue.global.3.2.38.js:7)
    4. at ye.fn (vue.global.3.2.38.js:7)
    5. at ye.run (vue.global.3.2.38.js:7)
    6. at L.e.update (vue.global.3.2.38.js:7)
    7. at L (vue.global.3.2.38.js:7)
    8. at P (vue.global.3.2.38.js:7)
    9. at F (vue.global.3.2.38.js:7)
    10. at g (vue.global.3.2.38.js:7)
    11. at ne (vue.global.3.2.38.js:7)

    再看下数据定义方法(home.js):

    1. const {createApp} = Vue
    2. createApp({
    3. data() {
    4. return {
    5. user: {
    6. username: "请输入手机号/邮箱",
    7. password: "请输入密码",
    8. },
    9. username: "请输入用户名",
    10. password: "请输入密码",
    11. }
    12. }
    13. }).mount('#app')

    再看下使用方法:

    1. html>
    2. <html lang="en">
    3. <head>
    4. <script src="/js/vue.global.3.2.38.js">script>
    5. head>
    6. <body>
    7. <div id="app">
    8. <input type="text" :placeholder="username" />
    9. <input type="text" :placeholder="user.password" />
    10. div>
    11. <script src="/js/home.js">script>
    12. body>
    13. html>

    就是这么简单,就是这么神奇,username是OK的,user.password就是不行,死活不行,看了网上的资料,官网的用法,看了一遍又一遍,快放弃了,算了,是不是user是关键字,于是,换了个写法,把user换成了userOne,问题就解决了。

    1. <input type="text" :placeholder="userOne.username" />
    2. <input type="text" :placeholder="userOne.password" />

  • 相关阅读:
    vue 针试打印机实现
    js 模糊定位标签元素
    [ 基础漏洞篇 ] webpack 前端源码泄露详解
    左值和右值
    PRC是什么 | 图解系列
    吴恩达机器学习 第一课 week2 基于Scikit-Learn的线性回归
    记录访问http链接,刷新页面会自动转到https问题
    [Spring Cloud] RestTemplate跨进程调用
    【周赛复盘】力扣第 85 场双周赛
    uos服务器系统安装达梦8数据库
  • 原文地址:https://blog.csdn.net/csdou/article/details/126856979