我正在使用moment.js,但是当我测试moment.js库时,我继续收到错误.
var back30Days=moment().subtract(30, 'days').format("dddd, MMMM Do YYYY, h:mm:ss p");
Run Code Online (Sandbox Code Playgroud)
它返回" moment not defined."指的是.format("dddd, MMMM Do YYYY, h:mm:ss p");
我已经阅读了文档,一切看起来都很好,但是当我重新加载页面时,我正在使用的js将无法加载.
任何提示将非常感谢!
以下是我的连接请求代码:
doLogin(this.login).then(response => {
var token = response.data.token;
localStorage.setItem('AUTH_TOKEN', JSON.stringify(token));
this.$router.push({name: 'Devices'});
});
}).catch(error => {
console.log(error.response.data.message);
});
Run Code Online (Sandbox Code Playgroud)
该catch()部分工作正常的HTTP错误(例如400,404,403...等).但是当我的服务器离线时,这个脚本就会抛出net::ERR_CONNECTION_REFUSED.有没有办法处理此错误并让前端用户知道服务器当前处于脱机状态.
这是doLogin()函数以防万一,
function doLogin(data) {
const url = 'http://localhost:3000/authenticate';
return axios.post(url,data);
}
Run Code Online (Sandbox Code Playgroud) 更新我的名单时,我是有问题的NG-重复的观点和$范围.$适用前来救援.我关注观察者.使用$ scope.$ apply()经常是一个好习惯吗?由于我在应用程序中有很多视图,必须在按钮单击时立即更新.
PS:任何替代方案都表示赞赏.
我的应用程序的示例JS代码:
function onRefreshList() {
vm.showLoader = true;
GetDataService.getVotes(someParams).then(function(res) {
if (res){
vm.showLoader = false;
vm.voteList = res; //voteList will be updated on click of Refresh list
$scope.$apply(); //working fine with this }
}).catch(function (res) {
vm.showLoader = false;
console.log("There was an error will loading votes");
})
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div ng-show="showLoader">
<ion-spinner icon="android" class="spinner-assertive"></ion-spinner>
</div>
<div ng-show="!showLoader" ng-repeat="vote in votesCtrl.voteList">
{{vote}}
</div>
Run Code Online (Sandbox Code Playgroud) 我希望得到这样的效果:
假设如下:
有什么问题:我不知道如何使每张照片适合不同屏幕宽度的帧宽
我的代码:
jQuery(document).ready(function($) {
var $zdjecie = $('.woocommerce ul.products li.product img');
$('.woocommerce ul.products li.product').hover(
function() {
$(this).find('img').css({
'transform': 'scale(1)',
'top': '0',
'position': 'relative'
});
},
function() {
$(this).find('img').css({
'transform': 'scale(1.6, 1.5)',
'top': '',
'position': 'relative'
});
})
})Run Code Online (Sandbox Code Playgroud)
//the height of frame is different regardless of screen wide
.woocommerce ul.products li.product a img {
-webkit-transform-origin: center;
-ms-transform-origin: center;
transform-origin: center;
transform: scale(1.6, 1.5);
top: 60px; // here may be problem
position: relative;
-webkit-transition: transform 0.4s …Run Code Online (Sandbox Code Playgroud)在添加其他子项之前,我正在尝试删除结构中的所有子节点.
我在这里读过jQuery empty()回调没有被解雇,我可以做.empty(),然后我的代码到底.
所以我在这里转载了我的用例
//document.getElementById("labelEnv").innerHTML ="";
$("#labelEnv").empty()
$("<input type='text' class='input-field env' value='I wont be added'/>").insertBefore($('.addEnv'));Run Code Online (Sandbox Code Playgroud)
.form-style-2{
max-width: 600px;
padding: 10px 10px 2px 10px;
font: 13px Arial, Helvetica, sans-serif;
background: rgba(blue, 0.8);
}
.form-style-2-heading{
color:black;
font-weight: bold;
font-style: italic;
border-bottom: 2px solid #ddd;
margin-bottom: 20px;
font-size: 15px;
padding-bottom: 3px;
}
.form-style-2 label{
display:table;
width: 100%;
font-size: 15px;
}
.form-style-2 label > span{
color: black;
font-weight: bold;
padding-right: 5px;
width:25%;
display: table-cell;
}
.form-style-2 span.required{
color:red;
}
.form-style-2 …Run Code Online (Sandbox Code Playgroud)我遇到的麻烦是,我必须根据窗口的内部宽度进行一些计算,但是每当我更改窗口宽度时,我的计算属性都不会被触发,我该如何让它工作?
这是我的简单代码:
var vm = new Vue({
el: '#elment',
computed: {
calculation: function(){
console.log(window.innerWidth)
return window.innerWidth;
}
}
})
Run Code Online (Sandbox Code Playgroud)
控制台打印我刚开始时的宽度 1x。我如何使其具有反应性?我的另一种方法是在已安装的钩子中向主体添加一个事件侦听器,并在那里进行计算。
请参阅以下代码段.
.frame {
height:10em;
padding:2px;
border:solid 1px black
}
.title {
height:2em;
overflow-y:scroll;
border:solid 1px green
}
.body {
height:100%; //??
overflow-y:scroll;
border:solid 1px red
}
.footer {
border:solid 1px blue
}Run Code Online (Sandbox Code Playgroud)
<div class="frame">
<div class="title">
headline
</div>
<div class="body">
<p>... body ... </p>
</div>
<div class="footer">
<textarea style="height:2em;width:95%"></textarea>
</div>
<div>Run Code Online (Sandbox Code Playgroud)
是否有可能使红色(.body)div填满绿色(.title)和蓝色(.footer)div之间的间隙,并使所有三个完全适合黑色框架而不在脚本中计算高度?
我正在开发一个聊天功能(使用 Vue),并且正在使用 textarea 作为我的输入,因此溢出包装并且对于编写更长消息的用户来说更具可读性。不幸的是,当用户按下回车键并提交时,光标会在提交前移动到一个新行,让 UX 感觉不对。关于如何使用 vanilla Javascript 在提交时禁用换行符的任何想法?如您所见,我尝试添加 replace() 函数但无济于事。
我的文本区域:
<textarea id="btn-input" type="text" class="input-group_input" rows="4"
placeholder="Type your message here..." v-model="body"
@keydown.enter="postReply()">
</textarea>
Run Code Online (Sandbox Code Playgroud)
我的提交方法:
postReply() {
this.$http.post('/api/chat/' + this.session.id + '/replies', {
body: this.body
}).then((response) => {
this.body.replace(/(\r\n|\n|\r)/gm,'');
this.body = '';
this.replies.unshift(response.data);
}).catch((error) => {
})
},
Run Code Online (Sandbox Code Playgroud) 我有一个电子邮件输入和一个观察者,用于检查输入是否有效。但是,只有当您在电子邮件字段中键入内容时才会触发 watch 事件。电子邮件字段的现有值可能无效,也可能无效。如果电子邮件无效,则显示 x,否则显示检查。但是,由于电子邮件具有现有值,因此即使输入无效,最初也会显示支票。如果用户清除了电子邮件字段,并重新输入了无效的电子邮件,那么这是唯一一次触发观察者并显示 x 的时间。
这是我的 vue 实例:
var register = new Vue({
el: '#register',
data: {
email: document.getElementById('profileEmail').value,
isEmailTaken: false,
emailTimer: null,
emailBusy: false
},
methods: {
validateEmail: function(email) {
var self = this;
var url '/api/users?email=' + email;
self.$http.get(url)
.then(function(res){
self.isEmailTaken = true;
self.emailBusy = false;
}, function(err){
self.isEmailTaken = false;
self.emailbusy = false;
});
},
watch: {
email: function(val) {
var self = this;
clearTimeout(self.emailTimer);
self.emailBusy = true;
self.emailTimer = setTimeout(function() {
self.validateEmail(val);
}, 1600);
} …Run Code Online (Sandbox Code Playgroud)