我需要在我的 vue js 项目中使用一个简单的跟踪服务......
在我的 app.js 中,我可以通过两种方式使用它......
例如:-
1)创建原型:
import moment from 'moment';
Object.defineProperty(Vue.prototype, '$moment', { value: moment });
Run Code Online (Sandbox Code Playgroud)
2)使用插件将服务合并到其中:
import axios from 'axios';
export default {
install: function(Vue,) {
Object.defineProperty(Vue.prototype, '$http', { value: axios });
}
}
Run Code Online (Sandbox Code Playgroud)
两者都使用原型,并且两种方法都适合我...我只需要知道这两种方法之间的区别...
我已经完成了一些教程,最后在离子框架中发现了一些关于这一点.....
他们给出了一些使用离子原生的代码,我通过嵌入下面的代码做了同样的事情:
//Display OS name and version (Start)
import { Device } from 'ionic-native';
console.log('Device OS is: ' + Device.device.platform);
console.log('Device OS Version is: ' + Device.device.version);
//Display OS name and version (End)
Run Code Online (Sandbox Code Playgroud)
使用离子服务时,我在控制台中得到了这个:
'Device OS is: undefined'
'Device OS version is: undefined'
Run Code Online (Sandbox Code Playgroud)
然后我猜它不会在浏览器中工作,我尝试在我的手机中构建和运行,但仍然是相同的日志来...
PS:我刚刚开始使用离子
先感谢您 :)