我正试图循环Filelist:
console.log('field:', field.photo.files)
field.photo.files.forEach(file => {
// looping code
})
Run Code Online (Sandbox Code Playgroud)
你可以看到field.photo.files有一个Filelist:
如何正确循环field.photo.files?
我想获得我的Angular应用程序的基本路径.
现在我这样做: $scope.baseUrl = '$location.host()
但我只能得到这个:/localhost.我目前的baseURL是http://localhost:9000/.
我正在构建一个实用程序函数,它应该搜索属性名称并在找到它后返回其值.它应该递归地执行此操作:
// Function
util.findVal = (object, propName) => {
for (let key in object) {
if (key === propName) {
console.log(propName)
console.log(object[key])
return object[key]
} else {
util.findVal(object[key], propName)
}
}
}
// Input
object: {
photo: {
progress: 20
}
}
// Usage
util.findVal(object, 'progress')
Run Code Online (Sandbox Code Playgroud)
然而,控制台日志永远存在,浏览器崩溃.我究竟做错了什么?
编辑:
这就是我调用函数的方式:
// Input
item: {
photo: {
file: {},
progress: 20
}
}
this.findProgress(item)
methods: {
findProgress (item) {
return util.findVal(item, this.propName)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在处理旋转甚至change:
<div @change="handleRotate"></div>
<script>
export default {
data: {
rotate = 0
},
methods: {
handleRotate () {
this.rotate = this.rotate + this.getRotateAngle(e.clientX, e.clientY)
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
现在,第二个this.rotate运行在每个change.我该怎么做才能使第二次this.rotate只handleRotate运行第二次?
我有一个数组:
basicForm.schema = [
{},
{} // I want to watch only this
]
Run Code Online (Sandbox Code Playgroud)
我试过这样做:
‘basicForm.schema[1].value’: {
handler (schema) {
const plan = schema.find(field => {
return field.name === ‘plan’
})
},
deep: true
},
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误:
vue.js?3de6:573 [Vue警告]:观看路径失败:"basicForm.schema [1]"Watcher只接受简单的点分隔路径.要完全控制,请改用函数.
这样做的正确方法是什么?
以下函数从url获取和映像,加载它,并返回其宽度和高度:
function getImageData (url) {
const img = new Image()
img.addEventListener('load', function () {
return { width: this.naturalWidth, height: this.naturalHeight }
})
img.src = url
}
Run Code Online (Sandbox Code Playgroud)
问题是,如果我做这样的事情:
ready () {
console.log(getImageData(this.url))
}
Run Code Online (Sandbox Code Playgroud)
我得到undefined因为函数运行但imaged尚未加载.
如何使用await/async仅在照片加载且宽度和高度已经可用时返回值?
我的提交看起来像这样:
alex@alex-M52AD-M12AD-A-F-K31AD:~/node/project$ git log
commit 050e4417634300e724b8e0c29bb8b7a240a9a996
Author: alexcheninfo <alexchen.info@gmail.com>
Date: Fri Feb 12 12:55:38 2016 +0800
Rename documents
commit 637bd5ac976118d7e0fb3bf5f2bab950ce0ebb66
Author: alexcheninfo <alexchen.info@gmail.com>
Date: Fri Feb 12 11:29:01 2016 +0800
Make sidenav a component
Run Code Online (Sandbox Code Playgroud)
我想更改提交消息Make sidenav a component.我想使用git -ammend但我认为它只能用于更改上次提交的消息?
我收到以下错误:
ERROR in ./src/main.js
error Parsing error: The keyword 'import' is reserved
/Users/staging/Desktop/sourcetree/viewer_web/src/main.js:1:1
import Vue from 'vue'
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我的项目中的ES6功能无法识别?
我正在使用Node 5.0,这是我的package.json:
{
"name": "istaging-viewer",
"description": "A Vue.js project",
"author": "Alex <alexchen.info@gmail.com>",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"build": "rimraf dist && webpack --progress --hide-modules --config build/webpack.prod.conf.js",
"test": "karma start build/karma.conf.js --single-run"
},
"dependencies": {
"aframe": "mozvr/aframe#dev",
"bootstrap": "^3.3.6",
"jquery": "^2.2.1",
"lodash": "^4.4.0",
"vue": "^1.0.16",
"vue-resource": "^0.7.0",
"vue-router": "^0.7.11"
},
"devDependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": …Run Code Online (Sandbox Code Playgroud) 我试图改变这个:
"This is a test this is a test"
Run Code Online (Sandbox Code Playgroud)
进入这个:
["This is a", "test this is", "a test"]
Run Code Online (Sandbox Code Playgroud)
我试过这个:
const re = /\b[\w']+(?:[^\w\n]+[\w']+){0,2}\b/
const wordList = sample.split(re)
console.log(wordList)
Run Code Online (Sandbox Code Playgroud)
但我得到了这个:
[ '',
' ',
' ']
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
(规则是每N个字分割字符串.)
我有一个这样的逻辑:是用户是V2使用用户到url中subHeaderRouter.router.如果用户未启动this.openModal:
<router-link
v-for="subHeaderRouter in subHeaderRouters"
:to="subHeaderRouter.router"
@click="handleOpenModal()">
</router-link>
handleOpenModal () {
if (this.IsV2User) return
this.openModal('changeUserType', 'user.changeUserType')
}
Run Code Online (Sandbox Code Playgroud)
我现在唯一需要做的就是停止:to用户不是V2.怎么做到这一点?
javascript ×8
vue.js ×3
angularjs ×1
async-await ×1
asynchronous ×1
ecmascript-6 ×1
file ×1
git ×1
package.json ×1
promise ×1
recursion ×1
regex ×1
vuejs2 ×1