javascript - 如何在外部脚本中使用 nuxt 模块?
问题描述
我正在使用nuxt
. 我创建了一个名为 services 的目录,其中包含一些脚本。我想在脚本中使用@nuxt/device模块。模块的用法是这样的this.$device.isDesktop
。但是在外部脚本中,我无法访问nuxt
像this
.
我的项目结构是这样的:
我想在search_report.js
文件中使用这个包。的内容search_report.js
是这样的:
import Api from '~/services/api';
export default class SearchReport{
static instance = undefined;
search_query_id = undefined;
static get_instance(){
if(SearchReport.instance === undefined){
SearchReport.instance = new SearchReport();
}
return SearchReport.instance;
}
log_search_query(query, success_callback, error_callback){
let self = this;
Api.send_ajax_get('http://example.com/add_search_query/' + query + '/', data, function(result) {
self.search_query_id = result.data.search_query_id;
if(success_callback){
success_callback();
}
},error_callback);
}
}
我想在log_search_query
方法中使用这个包将设备类型发送到服务器。
如何nuxt-module
在外部脚本中使用 a?
解决方案
推荐阅读
- javascript - 删除动画子节点的动画迭代事件侦听器
- javascript - Axios 未在 Vuex 商店中正确设置 - Vue.js 和 Electron
- mysql - 一列是多个复合 FK 约束的一部分,是否有效且良好的设计决策?
- db2 - 如何计算数据为十进制时的时间差异?
- sql - SQL JOIN 将多个项目返回到 1 行
- debugging - 当消息不被理解时,Pharo 如何启动调试器?
- c# - JWT Bearer Authentication 不从标头中读取 Token
- c - 插入排序错误
- python - 如何摆脱 Python 中的 TLE 错误?
- sql - 如果选择为空,则查询以选择默认值