一、編寫
目錄結(jié)構(gòu)
|--項(xiàng)目名
|--|--src
|--|--|--utils
|--|--|--|--utils.js
utils.js
/**
* 獲取相對路徑
* @method getRelativePath
* @return {*} 返回主機(jī)地址
* @example http://172.19.82.130:8080/uploadfiles/summary/7c54efed-fbc0-49c0-8568-62b07b5c1816/temp/3.png
*/
let getRelativePath = url => {
let str = url.split("http://")[1]; //172.19.82.130:8080/uploadfiles/summary/7c54efed-fbc0-49c0-8568-62b07b5c1816/temp/3.png
if(str){
let pos = str.indexOf("/"); //獲取 相對路徑 在 str 的索引號,如:18
let relativePath = str.substring(pos + 1, url.length); //獲取相對路徑,如: uploadfiles/summary/7c54efed-fbc0-49c0-8568-62b07b5c1816/temp/3.png
return relativePath;
}
};
export { getRelativePath };
二响蕴、使用
utils.vue
<script>
import { mapActions } from 'vuex';
import { getRelativePath } from '@/utils/utils';//A.引用其中某幾個方法
//const utils = require('@/utils/utils');//B.全部引用
export default {
methods:{
let relativePath = getRelativePath(this.canvasBgInfo.url);//A
//let relativePath = utils.getRelativePath(this.canvasBgInfo.url);//B
}
}
</script>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者