nativescript - Nativescript Vue 核心模块
问题描述
我无法理解如何在 nativescript-vue 中使用框架模块。
例如这个模块,是我试图了解如何使用的: https ://docs.nativescript.org/ns-framework-modules/platform
我需要在 App.js / Main.js 或我要使用的组件中声明吗?
我来自 Vue.js 的 Web 开发,我认为我尝试遵循的实现示例如下所示:
这是我认为与移动设备中的实现方式相同的网络示例。
在网络上,如果我需要使用 Axios,我会将其导入 App.js / Main.js 以在应用程序中保持全局,或者将 SPF 导入以保持本地并能够调用所需的组件。
在移动设备中,如果我使用纯 nativescript 导入是明确的,但在 nativescript-vue 中我无法理解如何使用它,我不知道它是否已经默认配置。
解决方案
在代码中需要它们的地方导入模块,包括 app.js 和 SPF。
应用程序.js
import axios from "axios";
var platform = require("tns-core-modules/platform");
var instance = axios.create({ baseURL: "https://myendpoint.com" });
if (platform.isAndroid) { /* ... */ }
文件.vue
import axios from "axios";
var platform = require("tns-core-modules/platform");
export default {
methods: {
androidFunc() {
if (platform.isIOS) {
axios.get("https://website.com/api/ios") // ...
}
}
}
}
如果我需要全局的东西,我通常使用 Vue 实例属性 (Vue.prototype.$myProperty) 或 Vuex 存储。
推荐阅读
- visual-studio - 有没有办法让图片框在VB中保存一个值?
- linkedin - 在 LinkedIn 公司页面上发布
- nuget - 为 NuGet.Server v3.4.1.0 配置的额外文件夹在哪里导致 404 Not Found 错误
- javascript - 如何将嵌套对象数组转换为javascript中的对象?
- firebase - 如何在反应原生 Firebase 中显示特定用户详细信息
- authentication - Google Oauth2 未发生授权重定向
- spring-boot - 无法从模板中保存带有其他文本详细信息的文件,这会导致“所需的请求部分‘文件’不存在”这个错误
- python - 如何使用列名作为变量基于 null/not null 过滤数据框?
- swift - 如何在 switch 语句中使用元组作为模式
- html - 使硒单击特定元素