Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

react组件里如何获取window对象?

我想在index.html文件里手动设置一些文案变量

<script>
    (function(){
        window.App = {
            TITLE = '测试'
        }
    })()
</script>

我在react组件通过点击某个按钮console.log(window.App.TITLE),提示TITLE未定义。如何在index.html设置window变量呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你这语法错误了吧

        window.App = {
            TITLE : '测试'
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...