• 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" />

  • 相关阅读:
    【微服务】RedisSearch 使用详解
    LintCode 1394 · Goat Latin (字符串处理题)
    Node.js初步学习
    纯CSS如何禁止用户复制网页的内容?
    Redis数据结构详解
    PostgreSQL基础语法
    SpringCloudAlibaba-3.分布式事务(Seata)
    48. 从零开始学springboot: 接入RocketMQ
    Pytorch ddp切换forward函数 验证ddp是否生效
    数据结构第28节 字典树
  • 原文地址:https://blog.csdn.net/csdou/article/details/126856979