【发布时间】:2019-06-10 14:37:37
【问题描述】:
我是前端开发的新手,所以我认为这个问题很基础,但我自己却找不到答案。 我想使用 Shopify App Bridge,这意味着使用 Polaris React 组件为 Shopify 应用创建 UI。 我是 JS、React 和 npm 的新手,但遵循了一些基本教程才能开始。 当我在https://polaris.shopify.com/components/get-started#navigation 看到“首先,将组件导入您的项目:”指令时,我迷失了方向。 我猜导入行应该是我的 js 文件中的第一行,但是当我添加导入行时,我的基本示例停止工作。 我尝试使用以下命令安装北极星: npm install @shopify/polaris --save
我添加导入行之前的文件:
我的 HTML 文件:
<html>
<head>
<link rel="stylesheet" href="https://sdks.shopifycdn.com/polaris/3.4.0/polaris.min.css" />
</head>
<body>
<div id="root"></div>
<!-- Load React. -->
<!-- Note: when deploying, replace "development.js" with "production.min.js". -->
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script src="scripts/test.js"></script>
</body>
</html>
我的 test.js 文件:
class Hello extends React.Component {
render() {
return React.createElement('div', null, `Hello ${this.props.toWhat}`);
}
}
ReactDOM.render(
React.createElement(Hello, {toWhat: 'World'}, null),
document.getElementById('root')
);
我的 package.json 文件:
{
"name": "somename",
"version": "1.0.0",
"dependencies": {
"@shopify/polaris": "^3.4.0",
"react": "^16.7.0",
"react-dom": "^16.7.0"
}
}
当我添加“从 '@shopify/polaris' 导入 {AppProvider, Button};”到了js文件的顶部,页面无法渲染,但是我不知道为什么。
为了能够导入组件,我缺少什么?
谢谢, -路易丝
【问题讨论】:
标签: javascript reactjs shopify polaris