解决方法:
ts混入的方法:https://www.cnblogs.com/zhongchao666/p/11207117.html
解决问题的方法:https://stackoverflow.com/questions/54413763/trading-view-typescript-emitted-no-output
解决方法:
修改tsconfig.json中的compilerOptions,将其中的"allowJs"设为true,如: “allowJs”: true
在tsconfig中的"include"字段中将js文件的路径添加进去。
{
"compilerOptions": {
...
"allowJs": true, // 允许编译javascript文件
"include": [
"src/**/*",
"types",
"./src/api/equipment/*.js" //匹配equipment下的所有js文件
],
...
validate找不到类型,此时可以使用类型断言,将 validate 断言成: HTMLFormElement
(this.$refs[aaaa] as HTMLFormElement).validate();
暂时的解决方法:先拿到对应的元素,定义其类型再拿到对应的方法
let flv:any = this.$refs.flvV
flv.endFlvVideo()
vue.config.js配置文件里css的requireModuleExtension: 改为true
使用类型断言
let ref = (this.$refs.queryForm as ElForm)
ref.resetFields()
引入vue-i18n配置文件中的i18n,在页面中采用i18n.t替换this.$t(’…’)
//
import i18n from "@/locales"
...
//js代码中
i18n.t('login.usernameRule')
this.$msgbox({
...
cancelButtonClass: "btnCancel",
...
})
// style
.btnCancel{
float: right;
margin-left: 10px;
}
mounted() {
this.chart = echarts.init((this.$refs.flowChart as any), "macarons");
this.chart.setOption(this.chartOptions);
window.addEventListener("resize", this.resizeChart);
this.$on("hook:beforeDestroy", () => {
window.removeEventListener("resize", this.resizeChart)
})
}
//resize
private resizeChart() {
this.chart.resize();
}
<div class="dialog" @touchmove.prevent.stop @mousewheel.prevent></div>
private mouseDown(e:MouseEvent) {
e.which == 1; //鼠标左键
e.which == 3; //鼠标右键
}
原因:鼠标移动时,不会存储所有的移动信息,而是通过取插值的方法取得鼠标位置信息,否则,系统会被鼠标移动拖垮。所以就会出现,移动过快时,出现断点的问题。
解决方案:使用相对于整个浏览器窗口的坐标来定位。
private mouseDown(e: MouseEvent) {
...
let a:DOMRect = this.timeSelect.getBoundingClientRect() // 获得相对于浏览器的坐标
this.offectXY[0] = e.clientX - a.x; //用相对于浏览器的坐标以免鼠标移动过快导致位置出错
...
this.selectBar.style.left = this.offectXY[0].toString() + "px";
//添加鼠标移动事件
document.onmousemove = (e: MouseEvent) => {
...
this.offectXY[1] = e.clientX - a.x;
this.selectBar.style.width = this.offectXY[1] - this.offectXY[0] + "px";
}
}
await命令,会阻塞代码,如果函数体中有一个await语句后面的promise变为reject,那么整个async函数都会中断执行。但是我们希望即使前一个异步操作失败,也不要中断后面的异步操作。解决办法:将await放在try …catch结构里面
this.loading = true;
try {
await UserModule.Login(this.loginForm);
} catch (error) {
console.log(error)
}
this.loading = false;
this.$router.push({
path: this.redirect || "/",
query: this.otherQuery,
});
解决方法:在调用方法的时候用catch捕获异常
...
this.$router.push({
path: this.redirect || "/",
query: this.otherQuery,
}).catch(err =>{ err })
...
原因:addRoutes 方法仅仅是注入新的路由,并没有剔除原有的其它路由
解决方法:使用router.addRoutes(routes)之前调用resetRouter()清空路由
//router.ts
...
export function resetRouter() {
const newRouter = createRouter();
(router as any).matcher = (newRouter as any).matcher; // reset router
}
...
//premission.ts
...
import { resetRouter } from "./router"
...
router.beforeEach(async (to: Route, from: Route, next: any) => {
...
resetRouter();
router.addRoutes(accessedRoutes);
...
}
el-select 默认以字符串进行匹配,现实情况中后端经常存整型,el-select 默认会原样输出
解决办法:el-option中的:value转为整形
<el-select size="mini" v-show="scope.row.show" v-model="scope.row.type">
<el-option
v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="parseInt(item.value)"
>
/el-option>
</el-select>