This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add Vue browser example (#2302)
* Adds Vue browser example * Removes pify; uses IPFS.create
- Loading branch information
Showing
14 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.DS_Store | ||
/node_modules | ||
/dist | ||
|
||
# local env files | ||
.env.local | ||
.env.*.local | ||
|
||
# Log files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# IPFS Vue app | ||
|
||
A minimal demonstration of how to use `js-ipfs` with `Vue`. | ||
|
||
 | ||
|
||
This project was bootstrapped with [Vue CLI](https://cli.vuejs.org/). | ||
|
||
## Project setup | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
### Compiles and hot-reloads for development | ||
|
||
```bash | ||
npm run serve | ||
``` | ||
|
||
### Compiles and minifies for production | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
### Run your tests | ||
|
||
```bash | ||
npm run test | ||
``` | ||
|
||
### Lints and fixes files | ||
|
||
```bash | ||
npm run lint | ||
``` | ||
|
||
### Customize configuration | ||
|
||
See [Configuration Reference](https://cli.vuejs.org/config/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['@vue/app'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "browser-vue", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"serve": "vue-cli-service serve", | ||
"build": "vue-cli-service build", | ||
"lint": "vue-cli-service lint" | ||
}, | ||
"dependencies": { | ||
"core-js": "^2.6.5", | ||
"ipfs": "file:../../", | ||
"vue": "^2.6.10" | ||
}, | ||
"devDependencies": { | ||
"@vue/cli-plugin-babel": "^3.9.0", | ||
"@vue/cli-plugin-eslint": "^3.9.0", | ||
"@vue/cli-service": "^3.9.0", | ||
"babel-eslint": "^10.0.1", | ||
"eslint": "^5.16.0", | ||
"eslint-plugin-vue": "^5.0.0", | ||
"vue-template-compiler": "^2.6.10" | ||
}, | ||
"eslintConfig": { | ||
"root": true, | ||
"env": { | ||
"node": true | ||
}, | ||
"extends": [ | ||
"plugin:vue/essential", | ||
"eslint:recommended" | ||
], | ||
"rules": {}, | ||
"parserOptions": { | ||
"parser": "babel-eslint" | ||
} | ||
}, | ||
"postcss": { | ||
"plugins": { | ||
"autoprefixer": {} | ||
} | ||
}, | ||
"browserslist": [ | ||
"> 1%", | ||
"last 2 versions" | ||
] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> | ||
<link rel="icon" href="<%= BASE_URL %>favicon.ico" /> | ||
<title>IPFS Vue</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong | ||
>We're sorry but browser-vue doesn't work properly without JavaScript enabled. Please enable it to | ||
continue.</strong | ||
> | ||
</noscript> | ||
<div id="app"></div> | ||
<!-- built files will be auto injected --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
<div id="app"> | ||
<ipfs-info /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import IpfsInfo from "./components/IpfsInfo.vue"; | ||
export default { | ||
name: "app", | ||
components: { | ||
IpfsInfo | ||
} | ||
}; | ||
</script> | ||
|
||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
#app { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
font-family: "Avenir", Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
} | ||
</style> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<template> | ||
<div class="ipfs-info"> | ||
<img class="ipfs-logo" alt="IPFS logo" src="../assets/logo.svg" /> | ||
<h1>{{ status }}</h1> | ||
<h2>ID: {{ id }}</h2> | ||
<h2>Agent version: {{ agentVersion }}</h2> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: "IpfsInfo", | ||
data: function() { | ||
return { | ||
status: "Connecting to IPFS...", | ||
id: "", | ||
agentVersion: "" | ||
}; | ||
}, | ||
mounted: function() { | ||
this.getIpfsNodeInfo(); | ||
}, | ||
methods: { | ||
async getIpfsNodeInfo() { | ||
try { | ||
// Await for ipfs node instance. | ||
const ipfs = await this.$ipfs; | ||
// Call ipfs `id` method. | ||
// Returns the identity of the Peer. | ||
const { agentVersion, id } = await ipfs.id(); | ||
this.agentVersion = agentVersion; | ||
this.id = id; | ||
// Set successful status text. | ||
this.status = "Connected to IPFS =)"; | ||
} catch (err) { | ||
// Set error status text. | ||
this.status = `Error: ${err}`; | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<!-- Add "scoped" attribute to limit CSS to this component only --> | ||
<style scoped> | ||
.ipfs-logo { | ||
height: 10rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Vue from 'vue'; | ||
import App from './App.vue'; | ||
import VueIpfs from './plugins/vue-ipfs'; | ||
|
||
// Load our IPFS plugin. | ||
Vue.use(VueIpfs); | ||
|
||
Vue.config.productionTip = false; | ||
|
||
new Vue({ | ||
render: h => h(App), | ||
}).$mount('#app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import IPFS from 'ipfs' | ||
|
||
const plugin = { | ||
install(Vue, opts = {}) { | ||
Vue.prototype.$ipfs = IPFS.create(opts) | ||
}, | ||
} | ||
|
||
// Auto-install | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(plugin) | ||
} | ||
|
||
export default plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
chainWebpack: config => config.resolve.symlinks(false), | ||
} |