admin管理员组文章数量:1353122
I am trying to get into stimulusJS
import { Controller } from 'stimulus'
export default class extends Controller {
static targets = [
'foo',
]
connect() {
const fooValue = this.fooTarget.value
console.log(this.fooValue) // 7
this.someFunction()
}
someFunction(){
console.log(this.fooValue) // undefined
}
}
I want to be able to get this value on connect as I want to know if it has changed.
I am trying to get into stimulusJS
import { Controller } from 'stimulus'
export default class extends Controller {
static targets = [
'foo',
]
connect() {
const fooValue = this.fooTarget.value
console.log(this.fooValue) // 7
this.someFunction()
}
someFunction(){
console.log(this.fooValue) // undefined
}
}
I want to be able to get this value on connect as I want to know if it has changed.
Share Improve this question edited May 28, 2022 at 20:34 ggorlen 57.9k8 gold badges114 silver badges157 bronze badges asked Aug 12, 2020 at 17:46 MZaragozaMZaragoza 10.1k9 gold badges74 silver badges116 bronze badges1 Answer
Reset to default 11Your code declares const
variable within the scope of connect()
function. But you should use this
(Stimulus Controller) property instead:
...
connect() {
this.fooValue = this.fooTarget.value
...
本文标签: javascriptStimulusJS How to set an instance variable on connectStack Overflow
版权声明:本文标题:javascript - StimulusJS How to set an instance variable on connect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743925283a2562847.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论