小程序-報錯 xxx is not defined (已解決)


小程序-報錯 xxx is not defined (已解決)

問題情境:
這樣一段代碼,微信的小程序報錯 is not defined

我 wxml 想這樣調用

//wxml 代碼
<view class='ltext'>{{_typeTitle}}</view>

我出錯的情況是這樣的

//程序 js 代碼
Page({
data: {
    titleArray: ['01 某試玩平台', ‘02 某試玩平台’,'03 ...' ],
},

onLoad: function (options) {
    var that = this;
    var _typeTitle = titleArray[1];
  
    that.setData({
         _typeTitle: _typeTitle, 
   })
},
})

為什么在 data 里定義了,還是不能用呢

這是,新手在學習時,常見錯誤之一,不能直接使用 名字調用

正確的方式

//程序 js 代碼
Page({
data: {
    titleArray: ['01 某試玩平台', ‘02 某試玩平台’,'03 ...' ],
},

onLoad: function (options) {
    var that = this;
    var _typeTitle = this.data.titleArray[1];


 that.setData({
         _typeTitle: _typeTitle, 
   })
},
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM