我正在建立一个基于Nuxt TypeScript Starter模板的网站。我已经在页面文件夹中创建了动态路由的页面_id.vue,并且希望可以访问TS类中的id属性。我可以通过写在模板中访问它,{{$route.params.id}}但是当我尝试$route在类内部引用时,出现错误:
错误TS2304:找不到名称'$ route'。
我有一个包含 2 个类的简单 TypeScript 项目:Main.ts 和 Ball.ts,首先是导入第二个。我正在尝试创建一个类似于 AS3 项目的设置,其中有一个入口点类可以触发所有其他事情的发生。我想将所有 js 编译成一个文件,以便我可以更有效地加载它。我有的文件:
主文件
import Ball from "./Ball";
class Main {
a: number = 10;
constructor() {
console.log("Hello from Main!");
let ball:Ball = new Ball();
}
}
let main = new Main();
Run Code Online (Sandbox Code Playgroud)
Ball.ts
export default class Ball{
shape:string = "round";
constructor(){
console.log("Ball has been created");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用的 TS 配置:
{
"compilerOptions": {
"target": "es5",
"module": "amd",
"outFile": "./public/js/bundle.js",
"strict": true
}
}
Run Code Online (Sandbox Code Playgroud)
要在 js 中使用 amd 模块,我使用 SystemJS:
<!DOCTYPE html>
<html …Run Code Online (Sandbox Code Playgroud) 有没有办法在 LESS 中创建无声的多行注释?我想要与 //comment 相同的行为,但对于多行字符串。
我正在将 Bootstrap-Vue 库集成到我的基于 Nuxt.js 的项目中。我通读了官方文档以开始使用,但尽管将 bt-vue 作为单个模块导入工作正常,但我希望能够导入单个组件和指令以减少生成的文件大小并使我的设置尽可能高效。文档仅为有关此主题的常规 Vue.js 项目提供了解决方案,但是我如何编写一个插件来使我能够对 Nuxt 执行相同的操作?
我开始创建一个bt-vue.ts插件,如下所示:
import Vue from 'vue'
import { Card } from 'bootstrap-vue/es/components';
Vue.use(Card);
Run Code Online (Sandbox Code Playgroud)
我已将此文件导入 nuxt.config.js 插件部分
plugins: [
...
'@/plugins/bt-vue'
...
]
Run Code Online (Sandbox Code Playgroud)
但是当我尝试编译我的项目时,我收到了这个错误:
node_modules\bootstrap-vue\es\components\index.js:1
(function (exports, require, module, __filename, __dirname) { import Alert from './alert';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require …Run Code Online (Sandbox Code Playgroud) nuxt.js ×2
typescript ×2
vue.js ×2
amd ×1
bootstrap-4 ×1
comments ×1
javascript ×1
less ×1
multiline ×1
systemjs ×1