苏人!
我在这里得到了这个HTML代码:
// index.html
<div data-init="component-one">
<...>
<div data-init="component-two">
<button @click="doSomething($event)">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果我正确地理解了一切,这基本上引用了另一个Vue实例中的Vue实例.相应的JS代码分为两个文件,如下所示:
// componentOne.js
new Vue(
el: '[data-init="component-one"]',
data: {...},
methods: {...}
);
// componentTwo.js
new Vue(
el: '[data-init="component-two"]'
data: {...}
methods: {
doSomething: function(event) {...}
}
);
Run Code Online (Sandbox Code Playgroud)
现在,问题在于doSomething,componentTwo永远不会被调用.
但是当我做一些内联的东西时,{{ 3 + 3 }}就像它应该计算一样.所以Vue知道有什么东西.它还会删除@click页面加载时的元素.
我也试着摆弄inline-template,但它并没有真正起作用,因为在这种情况下我会期待它.而且我认为它不适用于这种情况,所以我再次放弃了它.
这里的正确方法是什么?我怎样才能使这项工作成为现在最简单的方法?
我们使用的Vue版本是2.1.8.
干杯!
我真的很难在vue.js 2中使用最基本的REST功能.
我想从某个端点获取数据并将返回的值分配给我的Vue实例的变量.这是我有多远.
var link = 'https://jsonplaceholder.typicode.com/users';
var users;
Vue.http.get(link).then(function(response){
users = response.data;
}, function(error){
console.log(error.statusText);
});
new Vue ({
el: '#user-list',
data: {
list: users
}
});
Run Code Online (Sandbox Code Playgroud)
在promise中,我可以访问响应数据,但我似乎无法将其分配给用户甚至是Vue实例的数据.
毋庸置疑,我对vue.js全新,并感谢任何帮助.
Stack:vue.js 2.03,vue-resource 1.0.3
干杯!
我正在尝试get通过 axios 在 Vue 中发出 CORS请求。到目前为止一切正常,但如果我需要通过基本身份验证进行身份验证,我无法让它工作。
这是我的代码
getData: function() {
let vm = this; // assign vue instance to vm
axios.get('url', {
withCredentials: true,
auth: {
username: 'name',
password: 'pass'
}
}).then(function(response) {
console.log(response)
}).catch(function(error) {
console.log(error)
})
}
Run Code Online (Sandbox Code Playgroud)
即使我正确输入了凭据和 url,我也总是收到 401 响应。它看起来像这样。
HTTP/1.1 401 Authorization Required
Date: Wed, 01 Feb 2017 16:23:31 GMT
WWW-Authenticate: Basic realm="'Realm'"
Content-Length: 499
Keep-Alive: timeout=15
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
Run Code Online (Sandbox Code Playgroud)
原始请求看起来像这样
OPTIONS 'url' HTTP/1.1
Host: 'host'
Connection: keep-alive
Pragma: no-cache …Run Code Online (Sandbox Code Playgroud)