This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs: add Vue browser example #2302
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
{ | ||
"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:../../", | ||
"pify": "^4.0.1", | ||
"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 hidden or 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 hidden or 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 hidden or 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,51 @@ | ||
<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> | ||
import pify from "pify"; | ||
|
||
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 pify(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 hidden or 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 hidden or 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,22 @@ | ||
import IPFS from 'ipfs' | ||
|
||
function promisifyIpfs(opts) { | ||
return new Promise((resolve, reject) => { | ||
const node = new IPFS(opts) | ||
node.once('ready', () => resolve(node)) | ||
node.once('error', err => reject(err)) | ||
}) | ||
dbachko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const plugin = { | ||
install(Vue, opts = {}) { | ||
Vue.prototype.$ipfs = promisifyIpfs(opts) | ||
}, | ||
} | ||
|
||
// Auto-install | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(plugin) | ||
} | ||
|
||
export default plugin |
This file contains hidden or 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), | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.