MDC文本字段输入未向上浮动且向左

时间:2018-08-28 21:05:39

标签: javascript node.js material-design mdc-components material-components-web

我正在研究MDC 101 Tutorial,并使用webpack构建bundle.js文件。一切正常,除了标签没有向上浮动和向左浮动。我已经尝试过这两篇文章,但仍然无法正常工作。

  1. MDC Textfield does float top-left
  2. MDC Textfield not rendering

我认为这与我的JavaScript有关。这是webpack的javascript条目文件。

import {MDCRipple}    from '@material/ripple';
import {MDCSelect}    from '@material/select';
import {MDCTextField} from '@material/textfield';
import {MDCTopAppBar} from '@material/top-app-bar/index';


const topAppBarElement  = document.querySelector('.mdc-top-app-bar');
const topAppBar         = new MDCTopAppBar(topAppBarElement);


const textFieldElements = [].slice.call(document.querySelectorAll('.mdc-text-field'));
textFieldElements.forEach((textFieldEl) => {
  new MDCTextField(textFieldEl);
});


new MDCRipple(document.querySelector('.mdc-button'));
new MDCSelect(document.querySelector('.mdc-select'));

它在控制台中导致以下错误

bundle.js:230 Uncaught TypeError: Cannot read property 'querySelector' of null
    at D.initialize (bundle.js:230)
    at new a (bundle.js:34)
    at new D (bundle.js:230)
    at Module.<anonymous> (bundle.js:590)
    at i (bundle.js:1)
    at Object.<anonymous> (bundle.js:1)
    at i (bundle.js:1)
    at bundle.js:1
    at bundle.js:1

这句话,“这是JS来实例化两个文本字段(或其中任意数量的):...”,来自其中一篇文章,这使我认为它是javascript。预先谢谢你。

0 个答案:

没有答案
相关问题