首页 > 解决方案 > 将 next.js 更改为 node.js 时,JavaScript 文件在 html 中不起作用

问题描述

我之前写了一个 javascript,并使用 next.js 的指南运行它(npm run dev)并且它工作。现在我想使用 node.js(node app.js) 让它在我的 html 文件中运行,但它似乎不起作用。

在我使用“”的 html 中(index.js 是我以前使用 next.js 时创建的 js)并且我已经将 index.js 放入 assets/js

下面是 index.js

/*jshint esversion: 6 */
import styled from 'styled-components';

const TiltWrap = styled.div`
    perspective: 500px;
    text-align: center;
    display: grid;
    justify-content: center;
`;
const TiltStyles = styled.div`
    background-image: url('images/drone.jpg');
    background-size: contain;
    border: 1px solid grey;
    width: 300px;
    height: 200px;
    color: white;
    transform: 
    rotateX(${30}deg)
    rotateY(${20}deg)
    rotate(${50}deg);
    position: relative;
`;

const Index = ({pitch, roll, yaw}) => (
    <TiltWrap>
        Pitch: {pitch}
        Roll: {roll}
        Yaw: {yaw}
        <TiltStyles pitch={pitch} roll={roll} yaw={yaw} />
    </TiltWrap>
);

Index.defaultProps = {
    pitch: 0,
    roll: 0,
    yaw: 0,
};

export default Index;

//for the html, I used below
<script src="assets/js/index.js"></script>

我希望它在我的 html 中运行,但在我添加它之后,我的网站上什么也没发生(在 DreamWeaver 中也不起作用)我应该修改其他文件吗?像 package-lock.jason 吗?应用程序.js?

标签: javascripthtmlnode.jsnext.js

解决方案


推荐阅读