【问题标题】:React material ui snackbar always is the bottom how can i fix?React Material ui 小吃吧总是在底部,我该如何解决?
【发布时间】:2021-11-06 01:05:20
【问题描述】:

您好,我正在尝试使用材质 ui 创建一个小吃店。 反应版本 = 0.14 Material-ui版本=0.15.0

我找不到适合这个版本的 React 的东西,所以我决定使用 material-ui。它有效,但仅在屏幕底部打开。我怎样才能改变这个?例如,我怎样才能获得右上角。

我的代码:

import Snackbar from 'material-ui/Snackbar';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'

this.state = {
      open: false,
    };

 handleTouchTap = () => {
    this.setState({
      open: true,
    });
  };

  handleRequestClose = () => {
    this.setState({
      open: false,
    });
  };


 <div>
        <button
          onClick={this.handleTouchTap}> 
            SHOW NOTIFICATION
       <button>

        <Snackbar
          open={this.state.open}
          message="Event added to your calendar"
          autoHideDuration={4000}
          onRequestClose={this.handleRequestClose}
        />
      </div>

图片在这里:[通知图片1

【问题讨论】:

    标签: javascript html css reactjs material-ui


    【解决方案1】:

    只需添加anchorOrigin 即可更新位置:

    <Snackbar
      ...
      anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
    />
    

    【讨论】:

    • 感谢越南的回答。但是 material-ui 0.15.0 版本不被接受我认为是因为我尝试过但不起作用。
    • 是的。 V0 不支持更新位置。过时了
    猜你喜欢
    • 2018-07-03
    • 2018-09-12
    • 2018-09-13
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 2020-02-20
    • 2020-10-18
    • 2021-02-12
    相关资源
    最近更新 更多